Well auth()->user() returns null when no user is logged in. Also, you can't access the current logged in user in the constructor of the controller.
Can you show your code?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi,
I'm trying to use auth()->user() in controller but isn't giving any thing, when I added
middleware('auth:api') to route it's work but I want to use only one route for both authenticated and guest users
Please or to participate in this conversation.