lasthourcloud/app/Http/Controllers/Api/Resources.php

39 lines
1.2 KiB
PHP
Raw Normal View History

2024-03-07 10:35:00 +00:00
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Models\Project;
use Illuminate\Http\Request;
class Resources extends Controller
{
public function resources(Request $request)
{
$teamId = get_team_id_from_token();
if (is_null($teamId)) {
2024-03-07 11:27:23 +00:00
return invalid_token();
2024-03-07 10:35:00 +00:00
}
$projects = Project::where('team_id', $teamId)->get();
$resources = collect();
$resources->push($projects->pluck('applications')->flatten());
$resources->push($projects->pluck('services')->flatten());
foreach (collect(DATABASE_TYPES) as $db) {
$resources->push($projects->pluck(str($db)->plural(2))->flatten());
}
2024-03-07 10:35:00 +00:00
$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;
});
2024-03-07 10:35:00 +00:00
return response()->json($resources);
}
}