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

Faiza's avatar
Level 1

Retrieve online user info by sanctum token

Hi everybody!

I need some help on how can I get data of current online user only. What I want is when user A is log in, system will show only info of user A. I use sanctum for authentication. I use session for my web-based system. Here is the query that I use for my web-based system

$query = "SELECT * FROM job_register WHERE job_assign ='{$_SESSION['username']}'"

How can I implement this query to laravel 9?

0 likes
3 replies
RayC's avatar
RayC
Best Answer
Level 10

You can use auth(), will provide the system with the currently logged in user only.

auth()->user()->name;
Auth::user()->name; // Does the same

So re-write like this:

$query = JobRegister::where('job_assign', auth()->user()->name)->get();
Faiza's avatar
Level 1

@RayC Okay I'll try on it. Thank you for replying sir

Faiza's avatar
Level 1

@RayC Just come here again to say your answer works wonder. Thank you sir, Have a good day :)

Please or to participate in this conversation.