title: Not getting the role of the user from middleware while authencated
body: <p>I want to direct the user to their dashboard, but before that, I need their role. I am not receiving the role from my middleware. I tried a relation between the tables but its not working.</p>
  
  <p><strong>CustomerAuth Middleware</strong></p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Middleware;
  
  use Closure;
  use App\Http\Requests\Request;
  
  class CustomerAuth
  {
      /**
       * Handle an incoming request.
       *
       * @param  \Illuminate\Http\Request  $request
       * @param  \Closure  $next
       * @return mixed
       */
      public function handle($request, Closure $next)
      {
  
  
          if (!auth()-&gt;check()) {
              return $next($request);
          }
      else{
  dd(auth()-&gt;user()-&gt;roles);
          foreach (auth()-&gt;user()-&gt;roles as $role){
  
              if ($role-&gt;slug == 'admin' || $role-&gt;slug == 'product-admin' || $role-&gt;slug == 'logistic-admin' ){
  
                  return redirect()-&gt;route('customer.login-reset');
              }
          }
  
  
          foreach (auth()-&gt;user()-&gt;roles as $role){
  
              if ($role-&gt;slug == 'customer' ){
  
              return redirect()-&gt;route('customer.dashboard');
              }
          }
      }
      }
  
  }
  </code></pre>
  
  <p><strong>User Model</strong></p>
  
  <pre><code>&lt;?php
  
  namespace App\Models;
  
  use Illuminate\Notifications\Notifiable;
  
  class User extends BaseModel
  {
      protected $table='users';
      use Notifiable;
  
      /**
       * The attributes that are mass assignable.
       *
       * @var array
       */
      protected $fillable = [
          'username','name', 'email', 'password','profile_image','role_id'
      ];
  
      /**
       * The attributes that should be hidden for arrays.
       *
       * @var array
       */
      protected $hidden = [
          'password', 'remember_token',
      ];
  
      public function  roles(){
          return $this-&gt;belongsToMany(Role::class);
      }
  
  
  }
  </code></pre>
  
  <p>The <a href="https://i.stack.imgur.com/U7y6c.png" rel="nofollow noreferrer">error</a> I encounter is trying to get the property of a non-object.</p>