permissions on Twill
Good morning. Tell me how to properly allow a user with a specific role to perform certain actions?
I have a user role and I want him to be able to post only articles. Thought to override the method. But instead of publishing, an edit action is available.
protected function getIndexOption($option)
{
if (Auth::guard('twill_users')->user()->can('reviewer-permission')) {
$authorizableOptions = [
'publish' => 'publish',
];
}
$authorized = array_key_exists($option, $authorizableOptions) ? Auth::guard('twill_users')->user()->can($authorizableOptions[$option]) : true;
return ($this->indexOptions[$option] ?? $this->defaultIndexOptions[$option] ?? false) && $authorized;
}
![](https://utfs.io/f/dabfba0f-aaad-4efc-8ffa-555c0ab5a44c-l7ns2i.png)
1 Reply
found the answer:
protected function getIndexOption($option)
{
if (in_array($option, ['publish', 'edit'])) {
return Auth::guard('twill_users')->user()->can('reviewer-permission');
}
return parent::getIndexOption($option);
}