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 wheres 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')

<p>Add a scoper for a given ability.</p>

scopeAll(callable|string $callback)

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

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

No description

Details

__construct(string $modelClass)

Parameters

string $modelClass

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

<p>Add a scoper for a given ability.</p>

Parameters

callable|string $callback
string $ability

Return Value

ModelVisibility

ModelVisibility scopeAll(callable|string $callback)

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

Parameters

callable|string $callback <p>The callback can be a closure or invokable class, and should accept:</p> <ul> <li>\Flarum\User\User $actor</li> <li>\Illuminate\Database\Eloquent\Builder $query</li> <li>string $ability</li> </ul> <p>The callback should return void.</p>

Return Value

ModelVisibility

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

Parameters

Container $container
Extension $extension