with('user') ->when($request->string('category')->toString(), fn ($query, $category) => $query->where('category', $category)) ->when($request->has('approved'), fn ($query) => $query->where('approved', $request->boolean('approved'))) ->latest('created_at') ->paginate(20); return ToolResource::collection($tools); } public function store(StoreToolRequest $request): ToolResource { $tool = Tool::query()->create([ 'featured' => false, 'approved' => false, ...$request->validated(), 'user_id' => $request->user()->id, ]); return new ToolResource($tool->refresh()->load('user')); } public function show(Tool $tool): ToolResource { return new ToolResource($tool->load('user')); } public function update(UpdateToolRequest $request, Tool $tool): ToolResource { $tool->update($request->validated()); return new ToolResource($tool->load('user')); } public function destroy(Tool $tool): Response { $tool->delete(); return response()->noContent(); } }