Support the ongoing development of Laravel.io →
Authentication Blade
Last updated 2 years ago.
0

Did you ever get this figured out? It is not working for me as well.

0

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.

Last updated 8 years ago.
0

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
Last updated 8 years ago.
0

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.

0

Thank you @r0bdiabl0 . This should really be mentioned in the documentation. Laravel 5.4 also has this issue

0

Yay for PHP namespacing.

Last updated 7 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

lucasctd lucasctd Joined 18 Dec 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.