status !== 'active') { return response('Gone', 410); } // Get item $item = get_item($request->input('type'), $id); // Get folders within upload request $folderWithinIds = Folder::with('folders:id,parent_id') ->where('parent_id', $uploadRequest->id) ->get(['id']); // Then get all accessible folders within $accessibleParentIds = Arr::flatten([filter_folders_ids($folderWithinIds), $uploadRequest->id]); // Check privileges if (! in_array($item->parent_id, $accessibleParentIds)) { return response('Access Denied', 403); } // If request contain icon or color, then change it if ($request->input('type') === 'folder' && $request->hasAny(['emoji', 'color'])) { ($this->updateFolderProperty)($request, $id); } // Update item $item->update(['name' => $request->input('name')]); if ($request->input('type') === 'folder') { return new FolderResource($item); } return new FileResource($item); } }