Did you ever get this figured out? It is not working for me as well.
Just for reference, here is what I am doing that does not work. Mind you, the policy works in the controller so I know that I have the policy set up correctly:
MessagePolicy:
public function create($user)
{
return $user->UGID >= 1;
}
MessageController:
public function getCreate()
{
$this->authorize('create', Message::class);
return view('messages.create');
}
create.blade.php:
@can('create', Message::class)
<div>Create Message</div>
@else
<div>Cannot Create Message</div>
@endcan
Whenever I visit the create page, I always get the cannot create message no matter what UGID I have. It's not even hitting the policy to check. But the controller check does work.
I discovered that you need to use the full namespace with the class within the blade template like so:
@can('create', App\Message::class)
Code...
@endcan
Oh, sorry. I have not been accessing laravel.io for while. I gotta do what you are saying and "Mark it as Solution" after that.
Thank you btw.
Thank you @r0bdiabl0 . This should really be mentioned in the documentation. Laravel 5.4 also has this issue
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community