authorize('viewAny', Technology::class); $technologies = Technology::query() ->with('logoMedia') ->withCount('projects') ->when($request->filled('category'), fn ($q) => $q->where('category', $request->string('category'))) ->when($request->filled('radar_ring'), fn ($q) => $request->string('radar_ring')->toString() === 'none' ? $q->whereNull('radar_ring') : $q->where('radar_ring', $request->string('radar_ring'))) ->when($request->filled('search'), fn ($q) => $q->where('name', 'like', '%'.$request->string('search').'%')) ->orderBy('position') ->orderBy('name') ->paginate(perPage: min($request->integer('per_page', 25), 100)) ->withQueryString(); return TechnologyResource::collection($technologies); } public function store(TechnologyRequest $request): JsonResponse { $this->authorize('create', Technology::class); $technology = new Technology; $technology->fill(TranslatablePayload::merge($technology, $request->validated(), $technology->translatable)); // The column's default, and the panel's, stated here so the model // knows it too: otherwise the answer to a create without a category // would be missing the one the row was given. $technology->category ??= TechnologyCategory::Tool; $technology->save(); return TechnologyResource::make($this->loaded($technology))->response()->setStatusCode(201); } public function show(Technology $technology): TechnologyResource { $this->authorize('view', $technology); return TechnologyResource::make($this->loaded($technology)); } public function update(TechnologyRequest $request, Technology $technology): TechnologyResource { $this->authorize('update', $technology); $technology->fill(TranslatablePayload::merge($technology, $request->validated(), $technology->translatable)); $technology->save(); return TechnologyResource::make($this->loaded($technology)); } public function destroy(Technology $technology): JsonResponse { $this->authorize('delete', $technology); $technology->delete(); return response()->json(status: 204); } protected function loaded(Technology $technology): Technology { return $technology->load('logoMedia')->loadCount('projects'); } }