Преглед на файлове

Refactor: Fetch cities with eager loading and alphabetical sort

DenLopes преди 1 месец
родител
ревизия
91f2a24e61
променени са 1 файла, в които са добавени 3 реда и са изтрити 1 реда
  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