can('product.view'); } /** Whether the user may see this one. */ public function view(User $user, Product $product): bool { return $user->can('product.view'); } /** Whether the user may download the list as CSV or Excel. */ public function export(User $user): bool { return $user->can('product.export'); } /** Whether the user may add products. */ public function create(User $user): bool { return $user->can('product.create'); } /** Whether the user may add products from a spreadsheet. */ public function import(User $user): bool { return $user->can('product.import'); } /** Whether the user may change this one: the permission, and a row the model lets them change. */ public function update(User $user, Product $product): bool { return $user->can('product.edit') && $this->writable($product); } /** Whether the user may change products — a selection at once, or any one; each row is narrowed by `scopeWritable()`. */ public function updateAny(User $user): bool { return $user->can('product.edit'); } /** Whether the user may change the restricted columns. */ public function updateRestricted(User $user): bool { return $user->can('product.edit-restricted'); } /** Whether the user may delete this one: the permission, and a row the model lets them change. */ public function delete(User $user, Product $product): bool { return $user->can('product.delete') && $this->writable($product); } /** Whether the user may delete a selection of products; each row is narrowed by `scopeWritable()`. */ public function deleteAny(User $user): bool { return $user->can('product.delete'); } /** Whether the user may bring this one back from the trash. */ public function restore(User $user, Product $product): bool { return $user->can('product.restore') && $this->writable($product); } /** Whether the user may bring a selection back from the trash. */ public function restoreAny(User $user): bool { return $user->can('product.restore'); } /** Whether the user may delete this one for good. */ public function forceDelete(User $user, Product $product): bool { return $user->can('product.force-delete') && $this->writable($product); } /** Whether the user may delete a selection for good. */ public function forceDeleteAny(User $user): bool { return $user->can('product.force-delete'); } /** Whether the row is one the caller may change, by the model's own rule. */ private function writable(Product $product): bool { $query = Product::withTrashed(); return ! $query->hasNamedScope('writable') || $query->scopes(['writable'])->whereKey($product->getKey())->exists(); } }