title: Laravel group multiple Middleware
body: <p>In my application I have three user roles:</p>
  
  <ol>
  <li>user</li>
  <li>editor</li>
  <li>admin</li>
  </ol>
  
  <p>When editor logs into the admin section, some of the sections are hidden (users manage, system information etc.) and of course, the admin can see everything.</p>
  
  <p>So, for this purpose I've created two middleware: Admin and Editor. This is the code.</p>
  
  <p>Admin middleware.</p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Middleware;
  use Illuminate\Support\Facades\Auth;
  
  use Closure;
  
  class Admin
  {
      /**
       * Handle an incoming request.
       *
       * @param  \Illuminate\Http\Request  $request
       * @param  \Closure  $next
       * @return mixed
       */
      public function handle($request, Closure $next)
      {
          if(Auth::check()) {
            if(Auth::user()-&gt;role_id == 3) {
              return $next($request);
            }
          }
  
          return redirect('/');
  
      }
  }
  </code></pre>
  
  <p>Editor middleware:</p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Middleware;
  use Illuminate\Support\Facades\Auth;
  
  use Closure;
  
  class Editor
  {
      /**
       * Handle an incoming request.
       *
       * @param  \Illuminate\Http\Request  $request
       * @param  \Closure  $next
       * @return mixed
       */
      public function handle($request, Closure $next)
      {
          if(Auth::check()) {
            if(Auth::user()-&gt;role_id == 2) {
              return $next($request);
            }
          }
  
          return redirect('/');
  
      }
  }
  </code></pre>
  
  <p>Here's the part of the Kernel:</p>
  
  <pre><code>protected $routeMiddleware = [
  
  'admin' =&gt; \App\Http\Middleware\Admin::class,
  'editor' =&gt; \App\Http\Middleware\Editor::class,
  
  ];
  </code></pre>
  
  <p>Now I'm trying to build the routes that will be available to those user roles.
  If I do it only for the admin or the editor, it works fine, but when I combine them, the one user can login and the other cannot.</p>
  
  <p>Here's the code only for the admin and it works fine.</p>
  
  <pre><code>Route::middleware('admin')-&gt;group(function(){
  
    Route::get('/admin', 'PagesController@adminIndex');
    Route::resource('/admin/pages', 'PagesController');
    Route::resource('/admin/news', 'NewsController');
    Route::resource('/admin/users', 'UsersController');
    ...
  });
  </code></pre>
  
  <p>I've tried to combine them with this code, but it's not working (cannot login into the admin section at all):</p>
  
  <pre><code>Route::middleware(['admin', 'editor'])-&gt;group(function(){
  
    Route::get('/admin', 'PagesController@adminIndex');
    Route::resource('/admin/pages', 'PagesController');
    Route::resource('/admin/news', 'NewsController');
    Route::resource('/admin/users', 'UsersController');
    ...
  });
  </code></pre>
  
  <p>How can I solve this problem?</p>
  
  <p>P.S. Later I want to build a logic for the User role too, so there's must a way to combine the routes.</p>