query('projectNumber')) { $q->where('project_number', $num); } if ($name = $request->query('projectName')) { $q->where('project_name', $name); } if ($sinceUp = $request->query('updatedSince')) { $q->where('updated_at', '>=', Carbon::parse($sinceUp)); } if ($sinceCr = $request->query('createdSince')) { $q->where('created_at', '>=', Carbon::parse($sinceCr)); } $out = $q->get()->map(function ($p) { return [ 'Id' => $p->id, 'ProjectName' => $p->project_name, 'ProjectNumber' => $p->project_number, 'Departments' => $p->departments->pluck('id')->all(), 'UserIds' => $p->profiles->pluck('id')->all(), 'Updated' => $p->updated_at->toIso8601String().'Z', 'Created' => $p->created_at->toIso8601String().'Z', ]; }); return response()->json($out); } /** * GET /Projects/{id} */ public function show(int $id) { $p = Project::with(['departments', 'profiles'])->findOrFail($id); return response()->json([ 'Id' => $p->id, 'ProjectName' => $p->project_name, 'ProjectNumber' => $p->project_number, 'Departments' => $p->departments->pluck('id')->all(), 'UserIds' => $p->profiles->pluck('id')->all(), 'Updated' => $p->updated_at->toIso8601String().'Z', 'Created' => $p->created_at->toIso8601String().'Z', ]); } }