Refactor resource mapping in resources() method

This commit is contained in:
Andras Bacsai 2024-03-08 15:16:58 +01:00
parent 6688120aee
commit 8b9548a463

View File

@ -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);
}