vendredi 13 juillet 2018

Laravel cannot pass multiple middleware

recently i created two middlewares which is one for user called device, and one other for super user which is high level of admin. This is my middleware

Role Device Middleware

<?php

namespace App\Http\Middleware;

use Closure;

class RoleDevice
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if(Auth::check() && Auth::User()->role=='device'){
            return $next($request);
        }
        return redirect()->route('login')->with('danger',"You don't have an access");
    }
}

Role Device Super User

<?php

namespace App\Http\Middleware;

use Closure;
use Auth;
use User;
class RoleSuper
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if(Auth::check() && Auth::User()->role=='super'){
            return $next($request);
        }
        return redirect()->route('login')->with('danger',"You don't have an access");
    }
}

after i created the middlewares, i put into the routes which is one route could access two middlewares. Here is one of my route.

Route::get('/dashboard','DashboardController@index')->middleware(['rolesuper','roledevice'])->name('dashboard');

and when i try to log in into my website, it returns

You don't have an access

which is don't pass into the middleware.

i hope i get any comments above ! thanks.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire