class ModelPrivate implements ExtenderInterface

Some models, in particular Discussion and CommentPost, are intended to support a "private" mode, wherein they aren't visible unless some criteria is met. This can be used to implement anything from private discussions to post approvals.

When a model is saved, any "privacy checkers" registered for it will be run. If any privacy checkers return true, the is_private field of that model instance will be set to true. Otherwise, it will be set to false. Accordingly, this is only available for models with an is_private field.

In Flarum core, the Discussion and CommentPost models come with private support. Core also contains visibility scopers that hide instances of these models with is_private = true from queries. Extensions can register custom scopers for these classes with the viewPrivate ability to grant access to view some private instances under some conditions.

Methods

__construct(string $modelClass)

No description

checker(callable|string $callback)

<p>Add a model privacy checker.</p>

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

No description

Details

__construct(string $modelClass)

Parameters

string $modelClass

ModelPrivate checker(callable|string $callback)

<p>Add a model privacy checker.</p>

Parameters

callable|string $callback <p>The callback can be a closure or invokable class, and should accept:</p> <ul> <li>\Flarum\Database\AbstractModel $instance: An instance of the model.</li> </ul> <p>It should return <code>true</code> if the model instance should be made private.</p>

Return Value

ModelPrivate

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

Parameters

Container $container
Extension $extension