title: How to make my dashboard accessible only for admin and seller in laravel?
body: <p><code>DashboardController.php</code></p>
  <pre class="lang-php prettyprint-override"><code>class DashboardController extends Controller
  {
      function __construct()
      {
          $this-&gt;middleware('auth');
      }
      // codes.....
  
  }
  </code></pre>
  <blockquote>
  <p>Initially, I make a middlewire for any auth user to access this <strong>dashboard</strong>.</p>
  </blockquote>
  <p><strong>Goal:</strong> I want to make this <code>dashboard</code> for only <code>admin</code> and <code>seller</code>. So that normal user can not access dashboard route.</p>
  <p><strong>How to do that?</strong></p>
  <p><strong>Reference table</strong></p>
  <p><code>users</code> table</p>
  <pre class="lang-php prettyprint-override"><code>         Schema::create('users', function (Blueprint $table) {
              $table-&gt;id();
              $table-&gt;string('name');
              $table-&gt;string('email')-&gt;unique();
              $table-&gt;string('photo')-&gt;nullable();
              $table-&gt;timestamp('email_verified_at')-&gt;nullable();
              $table-&gt;string('password');
              $table-&gt;longText('cartitems')-&gt;nullable();
              $table-&gt;longText('wishlist')-&gt;nullable();
              $table-&gt;unsignedBigInteger('discount')-&gt;default(0);
              $table-&gt;rememberToken();
              $table-&gt;timestamps();
          });
  </code></pre>
  <blockquote>
  <p>This is <code>users</code> table.</p>
  </blockquote>
  <p><code>roles</code> table</p>
  <pre class="lang-php prettyprint-override"><code>       Schema::create('roles', function (Blueprint $table) {
              $table-&gt;id();
              $table-&gt;string('name');
              $table-&gt;string('display_name');
              $table-&gt;timestamps();
          });
  </code></pre>
  <blockquote>
  <p>This is <code>roles</code> table. And every user have a role such as <code>Superadmin</code>, <code>admin</code>, <code>seller</code> or<code>customer</code></p>
  </blockquote>
  <p><code>role_user</code> table</p>
  <pre class="lang-php prettyprint-override"><code>        Schema::create('role_user', function (Blueprint $table) {
              $table-&gt;id();
              $table-&gt;unsignedBigInteger('user_id');
              $table-&gt;foreign('user_id')-&gt;references('id')-&gt;on('users')-&gt;onDelete('cascade');
  
              $table-&gt;unsignedBigInteger('role_id');
              $table-&gt;foreign('role_id')-&gt;references('id')-&gt;on('roles')-&gt;onDelete('cascade');
  
              $table-&gt;timestamps();
          });
  </code></pre>
  <blockquote>
  <p>In this pivot table make a relationship between <code>users</code> and <code>roles</code> table.</p>
  </blockquote>
  <p><strong>I HAVE TRIED THESE STEPS</strong></p>
  <p><code>DashboardController.php</code></p>
  <pre class="lang-php prettyprint-override"><code>function __construct()
  {
      $this-&gt;middleware('admin');
  }
  </code></pre>
  <p><code>Kernel.php</code></p>
  <pre class="lang-php prettyprint-override"><code>   'admin' =&gt; \App\Http\Middleware\Admin::class,
  </code></pre>
  <p><code>Admin.php</code> [new Middlewire]</p>
  <pre class="lang-php prettyprint-override"><code>public function handle($request, Closure $next)
  {
      dd(Auth::user());
  }
  </code></pre>
  <blockquote>
  <p>But this <code>Admin.php</code> can't not access the current authenticated user.</p>
  </blockquote>
  <blockquote>
  <p>it shows <strong>null</strong></p>
  </blockquote>