-
Notifications
You must be signed in to change notification settings - Fork 330
Ability Options
Eric Kincl edited this page Nov 9, 2019
·
2 revisions
Arbitrary options may be set on Abilities as key/value pairs. Bouncer won't use these at all in determining if an action is allowed or disallowed; they are there purely for you the user to use however you may see fit. The data is stored in 'options' column of 'abilities' table as JSON data.
There are a few ways to get and set these options;
- Via the
Silber\Bouncer\Database\Ability
class/object using thesetOptionsAttribute()
andgetOptionsAttribute()
methods. See Example 1 below. Note that using setOptionsAttribute() will overwrite any Constraints you have set! - Passed as an array in the attributes array to the
to()
and other methods that take ability attribute arrays. The array inside the attribute array must have the key name ofoptions
. See Example 2 below. I am unsure if this will overwrite and constraints you have set; Test and report back.
Example 1:
$ability = new Silber\Bouncer\Database\Ability();
$ability->setOptionsAttribute([
'key1' => 'value1',
'key2' => 'value2'
]);
Example 2:
Bouncer::allow(auth()->user())->to('view', $document, [
'title' => "View $document->title",
'options' => ['meta' => 'This is too meta'],
]);