This code not working
@hasrole('writer')
I am a writer!
@else
I am not a writer...
@endhasrole
while this code is working
@if($user->hasRole('writer'))
I am following this link https://docs.spatie.be/laravel-permission/v2/basic-usage/blade-directives/
Without seeing your app it's hard to know why it's not working for you.
The tests in this package are passing, and here is how they are written:
https://github.com/spatie/laravel-permission/blob/057affa0b96d48dbdfdab2598d8f52c8ec85c2e6/tests/BladeTest.php#L111-L125
https://github.com/spatie/laravel-permission/blob/master/tests/resources/views/hasRole.blade.php
This stopped working for me too (it worked before).
For me it seems like @role('some-role') @endrole is not recoginzed as blade directive anymore - it is rendered on the HTML page.
The workaround is as already mentioned to use @if(auth()->user()->hasRole('some-role))
This is potentially due to the use of facade/ignition. It takes over the blade compiler causing the following to never fire thus no directives are loaded.
$this->app->afterResolving('blade.compiler', function (BladeCompiler $bladeCompiler) {
It was an ignition bug
https://github.com/facade/ignition/issues/12
Most helpful comment
It was an ignition bug
https://github.com/facade/ignition/issues/12