Access rights on Laravel gates not detected

265 views Asked by At

I want to create two access rights on the gate, namely isAdmin and isCustomer, but why is isCustomer not detected and is always directed to isAdmin. But whatever role I use to log in, it's always detected as admin.

AuthServiceProvider.php

public function boot()
{
    $this->registerPolicies();

    Gate::define('isAdmin', function($user) {
        return $user->role == 'admin';
    });

    Gate::define('isCustomer', function($user) {
        return $user->role == 'customer';
    });
}

Blade/View using '@can' directive

@can('isAdmin')
<li class="sidebar-item">
    <a class="sidebar-link waves-effect waves-dark sidebar-link"
       href="{{ asset('lte/monster-html/table-basic.html') }}" aria-expanded="false">
        <i class="me-3 fa fa-table" aria-hidden="true"></i>
        <span class="hide-menu">Pesanan</span>
    </a>
</li>
<li class="sidebar-item">
    <a class="sidebar-link waves-effect waves-dark sidebar-link"
       href="{{ asset('lte/monster-html/icon-fontawesome.html') }}" 
           aria-expanded="false">
        <i class="me-3 fa fa-font" aria-hidden="true"></i>
        <span class="hide-menu">Pembayaran</span>
    </a>
</li>
@elsecan('isCustomer')
<li class="sidebar-item">
    <a class="sidebar-link waves-effect waves-dark sidebar-link"
       href="{{ asset('lte/monster-html/table-basic.html') }}" aria-expanded="false">
        <i class="me-3 fa fa-table" aria-hidden="true"></i>
        <span class="hide-menu">Pesan Yok</span>
    </a>
</li>
@endcan
0

There are 0 answers