In the Laravel5.1ACL tutorial, according to the above tutorial, if the user table uses the Default user table, everything is smooth, but my ultimate goal is to manage permissions in the admin table in the background, so I changed all the users in the tutorial to admin. At this time, a problem occurred. In blade, @ can (& #039; edit-po... laravel5.1 ACL tutorial
According to the above tutorial, if the user table uses the Default user table, everything is smooth, but my ultimate goal is to manage permissions in the admin table in the background, so I changed all the users in the tutorial to admin. At this time, a problem occurred. In blade@can('edit-post')
And@can('delete-post')
All failed
So I switched to the Controller.
$admin = Auth::guard('admin')->user(); if($admin->can('edit-post')){ echo 1; }
1, yeah!
So I thought about whether it was in the template.can
Is the user table retrieved? So Iauth.php
Defaultguard
Changeadmin
'defaults' => [ 'guard' => 'admin', 'passwords' => 'users', ],
Successful! Yeah!
Okay, the problem is coming. I don't want to change it.auth.php
Mediumguard
In the template.can
Is the user of the admin table determined?
Reply content:
Laravel5.1 ACL tutorial
According to the above tutorial, if the user table uses the Default user table, everything is smooth, but my ultimate goal is to manage permissions in the admin table in the background, so I changed all the users in the tutorial to admin. At this time, a problem occurred. In blade@can('edit-post')
And@can('delete-post')
All failed
So I switched to the Controller.
$admin = Auth::guard('admin')->user(); if($admin->can('edit-post')){ echo 1; }
1, yeah!
So I thought about whether it was in the template.can
Is the user table retrieved? So Iauth.php
Defaultguard
Changeadmin
'defaults' => [ 'guard' => 'admin', 'passwords' => 'users', ],
Successful! Yeah!
Okay, the problem is coming. I don't want to change it.auth.php
Mediumguard
In the template.can
Is the user of the admin table determined?
After reading the source code, it does not seem to support it !!!
/** * Compile the can statements into valid PHP. * * @param string $expression * @return string */ protected function compileCan($expression) { return "
"; }
/** * Determine if the given ability should be granted for the current user. * * @param string $ability * @param array|mixed $arguments * @return bool */ public function check($ability, $arguments = []) { try { $result = $this->raw($ability, $arguments); } catch (AuthorizationException $e) { return false; } return (bool) $result; }
The template can be written like this, but it is very long. I saved the if content to a public function.
@if(Gate::forUser(Auth::guard('admin')->user())->allows('$priv'))@endif