| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- namespace App\Services;
- use App\Models\City;
- use Illuminate\Database\Eloquent\Collection;
- class CityService
- {
- public function getAll(): Collection
- {
- return City::with(["state:id,name", "country:id,name"])
- ->orderBy("name", "asc")
- ->get();
- }
- public function findById(int $id): ?City
- {
- return City::find($id);
- }
- public function create(array $data): City
- {
- return City::create($data);
- }
- public function update(int $id, array $data): ?City
- {
- $model = $this->findById($id);
- if (!$model) {
- return null;
- }
- $model->update($data);
- return $model->fresh();
- }
- public function delete(int $id): bool
- {
- $model = $this->findById($id);
- if (!$model) {
- return false;
- }
- return $model->delete();
- }
- // Add custom business logic methods here
- }
|