diff --git a/app/Http/Controllers/Api/RegionController.php b/app/Http/Controllers/Api/RegionController.php index 65c6f1b..627f819 100644 --- a/app/Http/Controllers/Api/RegionController.php +++ b/app/Http/Controllers/Api/RegionController.php @@ -28,7 +28,7 @@ class RegionController extends Controller public function show($id) { - $info = Region::with(['currentPlant', 'monitorModes'])->show()->findOrFail($id); + $info = Region::with(['currentPlant', 'monitorModes', 'category'])->show()->findOrFail($id); return $this->json(RegionResource::make($info)); } diff --git a/app/Http/Resources/RegionResource.php b/app/Http/Resources/RegionResource.php index 5141a3a..2f305ea 100644 --- a/app/Http/Resources/RegionResource.php +++ b/app/Http/Resources/RegionResource.php @@ -22,6 +22,9 @@ class RegionResource extends JsonResource 'area' => $this->area, 'description' => $this->description, 'category_id' => $this->category_id, + 'category_name' => $this->whenLoaded('category', function () { + return $this->category->name; + }, ''), 'category' => RegionCategoryResource::make($this->whenLoaded('category')), 'current_plant' => RegionPlantResource::make($this->whenLoaded('currentPlant')), 'position_x'=> $this->position_x,