I have installed backpack 4 and Spatie. https://github.com/spatie/laravel-permission
I have created 2 roles: Admin and Users in my back end admin panel(the CRUD that comes with Backpack).
I have then added 2 permissions: 1 called "read admin link" 1 called "read user link"
I have assigned the permissions to each role: read admin link = role of admin read user link = role of user
I see the permissions correctly assigned to the roles inside the admin panel.
Now on the left navbar, I would like to see 1 menu when logged as an admin or see another menu when logged as a user.
But I cannot get it to work:
<li>
<ul>
@if(auth()->backpack_user()->can('read admin link'))
<li class="nav-item"><a class="nav-link" href=""><i class="nav-icon fa fa-user"></i> <span>Can only
be seen by admins</span></a></li>
@endif
@if(auth()->backpack_user()->can('read user link'))
<li class="nav-item"><a class="nav-link" href=""><i class="nav-icon fa fa-user"></i> <span>Can only
be seen by users</span></a></li>
@endif
</ul>
</li>
It seems that this permission checker(while logged in) :
@if(auth()->backpack_user()->can('xxxxxxxxxxx'))
@endif
Cause this error:
Facade\Ignition\Exceptions\ViewException
Method Illuminate\Auth\SessionGuard::backpack_user does not exist. (View:
C:\laragon\www\demo\resources\views\vendor\backpack\base\inc\sidebar_content.blade.php)
This is my base.php setup:
'middleware_class' => [
App\Http\Middleware\CheckIfAdmin::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
// \Backpack\CRUD\app\Http\Middleware\UseBackpackAuthGuardInsteadOfDefaultAuthGuard::class,
],
Any idea why this is happening please?
Thank you