middleware(EnabledOnlyOnLocalhost::class); $this->middleware(EnsureFeaturesAreActive::using(AllowExternalProfileManagement::class))->except(['index', 'show']); $this->middleware(UserExceedsExternalProfileLimit::class)->only(['store', 'restore']); } public function index(IndexRequest $request, IndexAction $action): ExternalProfileCollection { $query = new Query($request->validated()); $builder = ExternalProfile::query()->where(ExternalProfile::ATTRIBUTE_VISIBILITY, ExternalProfileVisibility::PUBLIC->value); $user = Auth::user(); if ($user) { $builder->orWhereBelongsTo($user); } $externalprofiles = $query->hasSearchCriteria() ? $action->search($query, $request->schema()) : $action->index($builder, $query, $request->schema()); return new ExternalProfileCollection($externalprofiles, $query); } public function show(ShowRequest $request, ExternalProfile $externalprofile, ShowAction $action): ExternalProfileJsonResource { $query = new Query($request->validated()); $show = $action->show($externalprofile, $query, $request->schema()); return new ExternalProfileJsonResource($show, $query); } /** * @param StoreAction $action */ public function store(StoreRequest $request, StoreAction $action): ExternalProfileJsonResource { $validated = array_merge( $request->validated(), [ExternalProfile::ATTRIBUTE_USER => Auth::id()] ); $profile = $action->store(ExternalProfile::query(), $validated); return new ExternalProfileJsonResource($profile, new Query()); } public function update(UpdateRequest $request, ExternalProfile $externalprofile, UpdateAction $action): ExternalProfileJsonResource { $updated = $action->update($externalprofile, $request->validated()); return new ExternalProfileJsonResource($updated, new Query()); } public function destroy(ExternalProfile $externalprofile, DestroyAction $action): JsonResponse { $message = $action->forceDelete($externalprofile); return new JsonResponse([ 'message' => $message, ]); } }