append(':') ->append(AllowExternalProfileManagement::class) ->__toString(); $this->middleware(EnabledOnlyOnLocalhost::class); $this->middleware($isExternalProfileManagementAllowed)->except(['index', 'show']); $this->middleware(UserExceedsExternalProfileLimit::class)->only(['store', 'restore']); } /** * Display a listing of the resource. * * @param IndexRequest $request * @param IndexAction $action * @return ExternalProfileCollection */ public function index(IndexRequest $request, IndexAction $action): ExternalProfileCollection { $query = new Query($request->validated()); $builder = ExternalProfile::query()->where(ExternalProfile::ATTRIBUTE_VISIBILITY, ExternalProfileVisibility::PUBLIC->value); $userId = Auth::id(); if ($userId) { $builder->orWhereBelongsTo(Auth::user()); } $externalprofiles = $query->hasSearchCriteria() ? $action->search($query, $request->schema()) : $action->index($builder, $query, $request->schema()); return new ExternalProfileCollection($externalprofiles, $query); } /** * Display the specified resource. * * @param ShowRequest $request * @param ExternalProfile $externalprofile * @param ShowAction $action * @return ExternalProfileResource */ public function show(ShowRequest $request, ExternalProfile $externalprofile, ShowAction $action): ExternalProfileResource { $query = new Query($request->validated()); $show = $action->show($externalprofile, $query, $request->schema()); return new ExternalProfileResource($show, $query); } /** * Store a newly created resource. * * @param StoreRequest $request * @param StoreAction $action * @return ExternalProfileResource */ public function store(StoreRequest $request, StoreAction $action): ExternalProfileResource { $validated = array_merge( $request->validated(), [ExternalProfile::ATTRIBUTE_USER => Auth::id()] ); $profile = $action->store(ExternalProfile::query(), $validated); return new ExternalProfileResource($profile, new Query()); } /** * Update the specified resource. * * @param UpdateRequest $request * @param ExternalProfile $externalprofile * @param UpdateAction $action * @return ExternalProfileResource */ public function update(UpdateRequest $request, ExternalProfile $externalprofile, UpdateAction $action): ExternalProfileResource { $updated = $action->update($externalprofile, $request->validated()); return new ExternalProfileResource($updated, new Query()); } /** * Remove the specified resource. * * @param ExternalProfile $externalprofile * @param DestroyAction $action * @return ExternalProfileResource */ public function destroy(ExternalProfile $externalprofile, DestroyAction $action): ExternalProfileResource { $deleted = $action->destroy($externalprofile); return new ExternalProfileResource($deleted, new Query()); } /** * Restore the specified resource. * * @param ExternalProfile $externalprofile * @param RestoreAction $action * @return ExternalProfileResource */ public function restore(ExternalProfile $externalprofile, RestoreAction $action): ExternalProfileResource { $restored = $action->restore($externalprofile); return new ExternalProfileResource($restored, new Query()); } /** * Hard-delete the specified resource. * * @param ExternalProfile $externalprofile * @param ForceDeleteAction $action * @return JsonResponse */ public function forceDelete(ExternalProfile $externalprofile, ForceDeleteAction $action): JsonResponse { $message = $action->forceDelete($externalprofile); return new JsonResponse([ 'message' => $message, ]); } }