I am trying to implemnt ACL
using Laravel Polices and Gate. Below is my code.
UserPolcy:
class UserPolicy
{
use HandlesAuthorization;
public function isRoleAllowed(User $user, $role)
{
return in_array( $role , $user->getRoles());
}
}
AuthServiceProvider:
class AuthServiceProvider extends ServiceProvider
{
protected $policies = [
'App\Model' => 'App\Policies\ModelPolicy',
];
public function boot()
{
$this->registerPolicies();
// User Policy
foreach ( get_class_methods(new \App\Policies\UserPolicy) as $method ) {
Gate::define($method, "App\Policies\UserPolicy@{$method}");
}
}
}
How I am try to access isRoleAllowed in my controller,
Gate::allows('isRoleAllowed', 'APPROVE_INVOICE')
It is always return true. It is not executing isRoleAllowed function. I don't know where I am getting wrong.