with(['technologies', 'project.coverMedia']) ->unless($this->isPreview($request), fn (Builder $q) => $q->open()) // A call attached to an unpublished project must not leak it. ->where(fn (Builder $q) => $q ->whereNull('project_id') ->orWhereHas('project', fn (Builder $p) => $p->published())) ->when($request->filled('technology'), fn (Builder $q) => $q ->whereHas('technologies', fn (Builder $t) => $t ->whereIn('slug', (array) $request->input('technology')))) // "I have four hours a week" is the real filter people apply. ->when($request->filled('max_hours_per_week'), fn (Builder $q) => $q ->where('hours_per_week', '<=', $request->integer('max_hours_per_week'))) ->orderByRaw('hours_per_week is null, hours_per_week asc') ->paginate($this->perPage($request)) ->withQueryString(); return PublicCallResource::collection($calls); } public function show(Request $request, string $slug): PublicCallResource { $call = Call::query() ->with(['technologies', 'project.technologies', 'project.coverMedia']) ->whereSlug($slug) ->unless($this->isPreview($request), fn (Builder $q) => $q->open()) ->firstOrFail(); return PublicCallResource::make($call); } }