Think it comes from 5.6 upgrade guide, you can read more in docs here: https://laravel.com/docs/5.6/upgrade
Hope it solves it.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have Laravel instance that I am trying to upgrade to 5.7 (and Passport 7.0, from 5.6 and 5.0 respectively). The app exists solely to serve data through an API. I use Passport for user authentication - everything worked in 5.6/5.0. The error I am now getting on some API calls is that Auth::user(); return null - so any method on what should be the authenticated user crashes. This happens AFTER the route is authenticated. I do not see how this can happen.
In my code, I try to get the authenticated user in the many ways Laravel allow. Only the ones that refer to the auth.api guard work:
$user = Auth::user(); // FAILS
$user = Auth::guard('api')->user(); // WORKS
$user = auth()->user(); // FAILS
$user = $request->user(); // FAILS
$user = auth()->guard('api')->user(); // WORKS
This creates a problem for testing, where I generally use WithoutMiddleware and actingAs - now all these tests fail because they do not go through the api guard.
This all worked with the prior versions.
Any thoughts on what is happening and how to fix it? Thank you!!
Please or to participate in this conversation.