authorize('viewAny', MissingUrl::class); $missing = MissingUrl::query() ->where('status', $request->string('status', MissingUrlStatus::Pending->value)) ->when($request->filled('locale'), fn ($q) => $q->where('locale', $request->string('locale'))) ->when($request->filled('search'), fn ($q) => $q->where('path', 'like', '%'.$request->string('search').'%')) ->orderByDesc('hits') ->orderByDesc('last_seen_at') ->paginate(perPage: min($request->integer('per_page', 25), 100)) ->withQueryString(); return MissingUrlResource::collection($missing); } public function show(MissingUrl $missingUrl): MissingUrlResource { $this->authorize('view', $missingUrl); return MissingUrlResource::make($missingUrl); } /** * Only between pending and ignored: `resolved` is what writing a redirect * makes it, and claiming it without one would be a lie the next sighting * undoes anyway. */ public function update(Request $request, MissingUrl $missingUrl): MissingUrlResource { $this->authorize('update', $missingUrl); $data = $request->validate([ 'status' => ['required', Rule::in([MissingUrlStatus::Pending->value, MissingUrlStatus::Ignored->value])], ]); $missingUrl->update($data); return MissingUrlResource::make($missingUrl); } public function destroy(MissingUrl $missingUrl): JsonResponse { $this->authorize('delete', $missingUrl); $missingUrl->delete(); return response()->json(status: 204); } /** * Give the address a destination. The report is marked resolved by the * redirect being created, as from anywhere else. */ public function redirect(MissingUrlRedirectRequest $request, MissingUrl $missingUrl): JsonResponse { $this->authorize('redirect', $missingUrl); $redirect = Redirect::create([ 'from' => $missingUrl->path, 'is_enabled' => true, ...$request->validated(), ])->refresh(); return RedirectResource::make($redirect)->response()->setStatusCode(201); } }