From 8b9548a463dbd9e0ac72a5bb307bb79c189d4d47 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Fri, 8 Mar 2024 15:16:58 +0100 Subject: [PATCH] Refactor resource mapping in resources() method --- app/Http/Controllers/Api/Resources.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/Http/Controllers/Api/Resources.php b/app/Http/Controllers/Api/Resources.php index d3d313f3a..4032d26e2 100644 --- a/app/Http/Controllers/Api/Resources.php +++ b/app/Http/Controllers/Api/Resources.php @@ -22,6 +22,16 @@ public function resources(Request $request) $resources->push($projects->pluck(str($db)->plural(2))->flatten()); } $resources = $resources->flatten(); + $resources = $resources->map(function ($resource) { + $payload = $resource->toArray(); + if ($resource->getMorphClass() === 'App\Models\Service') { + $payload['status'] = $resource->status(); + } else { + $payload['status'] = $resource->status; + } + $payload['type'] = $resource->type(); + return $payload; + }); return response()->json($resources); }