Browse Source

Refactor: Fetch cities with eager loading and alphabetical sort

DenLopes 1 month ago
parent
commit
91f2a24e61
1 changed files with 3 additions and 1 deletions
  1. 3 1
      app/Services/CityService.php

+ 3 - 1
app/Services/CityService.php

@@ -9,7 +9,9 @@ class CityService
 {
     public function getAll(): Collection
     {
-        return City::orderBy("created_at", "desc")->get();
+        return City::with(["state:id,name", "country:id,name"])
+            ->orderBy("name", "asc")
+            ->get();
     }
 
     public function findById(int $id): ?City