class ModelVisibility implements ExtenderInterface
Model visibility scoping allows us to scope queries based on the current user.
The main usage of this is only showing model instances that a user is allowed to see. This is done by running a query through a series of "scoper" callbacks, which apply additional `where`s to the query based on the user. Scopers are classified under an ability. Calling `whereVisibleTo` on a query will apply scopers under the `view` ability. Generally, the main `view` scopers can request scoping with other abilities, which provides an entrypoint for extensions to modify some restriction to a query. Scopers registered via `scopeAll` will apply to all queries under a model, regardless of the ability, and will accept the ability name as an additional argument.
Methods
Add a scoper for a given ability.
Add a scoper scoper that will always run for this model, regardless of requested ability.
Details
at
line 43
__construct(string $modelClass)
at
line 66
ModelVisibility
scope(callable|string $callback, string $ability = 'view')
Add a scoper for a given ability.
at
line 87
ModelVisibility
scopeAll(callable|string $callback)
Add a scoper scoper that will always run for this model, regardless of requested ability.