How to get current user id in laravel 5.4
3 answers
You can access the authenticated user using the Auth facade:
use Illuminate\Support\Facades\Auth;
// Get the currently authenticated user...
$user = Auth::user();
// Get the currently authenticated user ID...
$id = Auth::id();
You can access the authenticated user with Illuminate \ Http \ Request
use Illuminate\Http\Request;
public function update(Request $request)
{
$request->user(); //returns an instance of the authenticated user...
$request->user()->id; // returns authenticated user id.
}
via the Auth helper function:
auth()->user(); //returns an instance of the authenticated user...
auth()->user()->id ; // returns authenticated user id.
+2
source to share