guardFileOwnsItsSharing($file); [$assignable, $targetName] = $this->resolveRequestedTarget( $request, __('Files can only be assigned to clients or groups.'), ); // Idempotent, so a retried request is safe — which matters more // here than on the web, where a human does not retry automatically. $this->sharing->assign($file, $assignable, $targetName); return new FileResource($file->fresh()?->load(['assignments.assignable']) ?? $file); } public function destroy(Request $request, File $file): FileResource { Gate::authorize('update', $file); $this->guardFileOwnsItsSharing($file); [$assignable, $targetName] = $this->resolveRequestedTarget( $request, __('Files can only be assigned to clients or groups.'), ); $this->sharing->unassign($file, $assignable, $targetName); return new FileResource($file->fresh()?->load(['assignments.assignable']) ?? $file); } }