1 year ago

Route for different user types

Posted 1 year ago by tha07

I have a project that is been setup for middleware as this way. This routes are available only for role 1 user role. I want them available for both role 1 & 2 user roles.

I tried adding 'auth', 'Role:1', 'Role:2' but it didn't work

my routes\web.php file

Route::group(['prefix' => ADMIN, 'as' => ADMIN . '.', 'middleware'=>['auth', 'Role:1']], function() {
    Route::get('/', '[email protected]')->name('dash');
    Route::resource('users', 'UserController');
    Route::resource('businesses', 'BusinessController');

my App\Http Kernal File

protected $routeMiddleware = [
    'Role' => \App\Http\Middleware\Role::class,

my App\Http\Middleware Role File

public function handle($request, Closure $next, $role)

        // Not Logged
        if (!Auth::check()) {
            return redirect('/login');

        // Not allowed
        if ($request->user()->role != $role) {
            return abort(404);

        return $next($request);

Please sign in or create an account to participate in this conversation.