Laravel multiple guard in blade

How make multiple watch same div to admin and manager using middleware?

Admin middleware

public function handle($request, Closure $next)
{
    if(Auth::check() && Auth::user()->isRole() == "Administrator"){
        return $next($request);
    }
    return redirect('login');
}

Manager middleware

public function handle($request, Closure $next)
{
    if(Auth::check() && Auth::user()->isRole() == "Manager"){
        return $next($request);
    }
    return redirect('login');
}

And AppServiceProvoider

public function boot()
{
    Blade::if('admin', function () {
        return auth()->check() && auth()->user()->role == "Administrator";
    });

    Blade::if('manager', function () {
        return auth()->check() && auth()->user()->role == "Manager";
    });
}

Upvotes: 0

Views: 219

Answers (1)

Andy Song
Andy Song

Reputation: 4684

why not do this?

    Blade::if('managerOradmin', function () {
        return auth()->check() && (auth()->user()->role == "Administrator" || auth()->user()->role == "Manager");
    });

Upvotes: 1

Related Questions