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

SimonAngatia's avatar

Is there a way I can access authenticated user information in an API route in Laravel?

I have a callback URL(mywebsite.com/final/results), which is a POST route, like:

Route::post('final/results','FinalResultsController@someMethod')

On this route, I am waiting for data that comes like

{"trx_id":"12","session":2,"method":"do","retry":true,"minus":20,"sign":"rthrtghert", "plus":0}

When the data comes, it is handled by the someMethod on FinalResultsController Now I need to get the logged-in information so that I can be able to update the user with the information. The problem is however that when I try to get the authenticated user through auth('api')->user(). it returns null. Is there any other way I can get the logged-in user information from the API route?

My project's Laravel version is 6.

0 likes
3 replies
Snapey's avatar

If its a callback (from an API or similar) then there won't be any user. Perhaps you need to pass something to the other party that they can indicate what they are posting back relates to?

You have a trx_id does that mean anything to your code? Have you seen it before?

SimonAngatia's avatar

trx_id has nothing to do with the current logged in user. But I need to return response with the user balance, meaning I have to access the logged-in user information.

Snapey's avatar

Where is the data coming from? If you get two posts, how do you know which one is which?

Please or to participate in this conversation.