Answer the question
In order to leave comments, you need to log in
How to create an abstract Gate::define() in Laravel?
How to create a generic action authorization function via Gate::define()?
Example:
//AuthServiceProvider.php
public function boot()
{
$this->registerPolicies();
$this->registerUserPermissionPolicies();
}
public function registerUserPermissionPolicies()
{
Gate::before(function($user, $ability) {
if ($user->isSuperAdmin()) {
return true;
}
});
Gate::define($ability, function($user, $ability) {
return $user->hasAccess($ability);
});
}
@can('ability'
$ability
//AuthServiceProvider.php
Gate::define('ability', function($user) {
return $user->hasAccess('ability');
});
//Anywhere.blade.php
@can('ability')
//Something
@endcan
Answer the question
In order to leave comments, you need to log in
Gate::before(function ($user, $ability) {
return $user->hasAccess($ability);
});
Gate::before(function ($user, $ability) {
if(in_array($ability, ['see_private_posts', 'delete_private_posts'])) {
return $user->hasAccess($ability);
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question