Daily Archives: 30th December 2017


Methods to obtain Laravel 5.5 user ID

Obtaining the user instance in Laravel Controller;

All these return the same result

dump($request->user()->id);        //using the $request variable passed into to controller

dump(request()->user()->id);        //using the request() helper method

dump(Auth::id());                   //using Auth facade

dump(Auth::user()->id);             //getting user object from Auth facade

dump(auth()->id());                 //using auth() helper

dump(auth()->user()->id);           //getting user object from auth helper

Methods that use the id from the user object will throw an error if there is no logged in user