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

__construct(string $modelClass)

No description

scope(callable|string $callback, string $ability = 'view')

Add a scoper for a given ability.

scopeAll(callable|string $callback)

Add a scoper that will always run for this model, regardless of requested ability.

void
extend(Container $container, Extension|null $extension = null)

No description

Details

__construct(string $modelClass)

Parameters

string $modelClass

ModelVisibility scope(callable|string $callback, string $ability = 'view')

Add a scoper for a given ability.

Parameters

callable|string $callback
string $ability

Return Value

ModelVisibility

ModelVisibility scopeAll(callable|string $callback)

Add a scoper that will always run for this model, regardless of requested ability.

Parameters

callable|string $callback

Return Value

ModelVisibility

void extend(Container $container, Extension|null $extension = null)

Parameters

Container $container
Extension|null $extension

Return Value

void