Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

gust's avatar
Level 1

Can I get the current users id from a session?

I'm making a quiz site and each user has many quizzes and each quiz has many questions i Have one form which I fill out the title,intro,image of the quiz and send it to quizcontroller which creates a new quiz row in the quiz table but each quiz needs a user_id and I'm not sure of the 'best' way to get it in order to save it to the DB(SQL)

0 likes
4 replies
CodeFox's avatar

Couldn't you just pass the user to the controller and do

Auth::user()->id

?

Snapey's avatar
Snapey
Best Answer
Level 122

Assuming you want just the id;

$request->user()->id;


Auth::user()->id;


//or just


Auth::id;

gust's avatar
Level 1

oh thanks,would one be better practice over the other?

gust's avatar
Level 1

Also are these query builder methods(user())? if so where can i find a complete list, the laravel site only has some examples

Please or to participate in this conversation.