title: Laravel Middleware -> get the logged in user
body: <p>I want to write my own middleware to check, if the current user is member of a certain grup. If yes, the user can move on to the route, if not, the user will be redirected to a different page.</p>
  
  <p>My middleware is working, but I don't know how to get the current users id. I've tried the Auth::user() method, but with no success.</p>
  
  <p>This is my Middleware:</p>
  
  <pre><code>namespace App\Http\Middleware;
  
  use Closure;
  use App\User;
  use App\Usergroups;
  use Illuminate\Http\Request;
  
  class UserGroupMiddleware
  {
       /**
       * Handle an incoming request.
       *
       * @param  \Illuminate\Http\Request  $request
       * @param  \Closure  $next
       * @return mixed
       */
       public function handle(Request $request, Closure $next, $group = NULL)
      {
          $user_id = $request-&gt;user()-&gt;user_id;
          $user = User::find($user_id);
          $usergroup = Usergroups::find($user-&gt;benutzergruppe);
  
          if($usergroup-&gt;slug == 'admin'){
              return $next($request);
          }
          return redirect('/');
      }
  }
  </code></pre>