getLocale(); $projects = Project::query() // `coverMedia` carries the dimensions and responsive versions of // the cover; loaded here so a listing costs one query, not one per // project. ->with(['technologies', 'lead', 'repositories', 'coverMedia', 'lead.avatarMedia', 'client.logoMedia']) ->withCount([ 'members', // Powers the `needs_help` flag without loading every call. 'calls as open_calls_count' => fn (Builder $q) => $q->open(), ]) ->unless($this->isPreview($request), fn (Builder $q) => $q->published()) ->when($request->filled('status'), fn (Builder $q) => $q ->whereIn('status', (array) $request->input('status'))) ->when($request->boolean('featured'), fn (Builder $q) => $q->where('is_featured', true)) ->when($request->boolean('needs_help'), fn (Builder $q) => $q->needingHelp()) ->when($request->filled('technology'), fn (Builder $q) => $q ->whereHas('technologies', fn (Builder $t) => $t ->whereIn('slug', (array) $request->input('technology')))) ->when($request->filled('member'), fn (Builder $q) => $q ->whereHas('members', fn (Builder $m) => $m ->where('slug', $request->string('member')))) // Only projects that actually exist in this language, so the // frontend never renders a listing of fallback content. ->when($request->boolean('translated'), fn (Builder $q) => $q ->whereNotNull("title->{$locale}")) ->orderByDesc('is_featured') ->orderBy('position') ->orderByDesc('published_at') ->paginate($this->perPage($request)) ->withQueryString(); return PublicProjectResource::collection($projects); } /** * GET /api/public/v1/projects/{slug} * * Resolution is by slug within the active locale — the access pattern an * SSR frontend actually has, since it receives a URL, not an id. */ public function show(Request $request, string $slug): PublicProjectResource { $project = Project::query() ->with([ 'technologies', 'coverMedia', 'images.media', 'client.logoMedia', 'services', 'testimonials' => fn ($q) => $q->public()->with('avatarMedia')->orderBy('position'), 'talks' => fn ($q) => $q->public()->with('member')->recentFirst(), 'lead', 'lead.avatarMedia', 'members.technologies', 'members.avatarMedia', 'repositories.goodFirstIssues', 'calls' => fn ($q) => $q->open()->with('technologies'), ]) ->whereSlug($slug) ->unless($this->isPreview($request), fn (Builder $q) => $q->published()) ->firstOrFail(); return PublicProjectResource::make($project)->detailed(); } }