can('delete_files'); $mayDeleteOthers = $viewer->can('delete_others_files'); $scoped = $viewer->isClientScoped(); if ($mayDeleteOwn && $mayDeleteOthers && ! $scoped) { return 0; } return File::query() ->whereIn('folder_id', $folder->subtreeFolderIds()) ->where(function (Builder $outer) use ($viewer, $mayDeleteOwn, $mayDeleteOthers, $scoped): void { if (! $mayDeleteOwn) { $outer->orWhere('uploaded_by', $viewer->id); } if (! $mayDeleteOthers) { $outer->orWhere(fn (Builder $others): Builder => $others ->whereNull('uploaded_by')->orWhere('uploaded_by', '!=', $viewer->id)); } if ($scoped) { $outer->orWhereNotIn('id', $this->scope->files($viewer)->select('id')); } }) ->count(); } }