Closed johnbacon closed 3 months ago
The problem is that auth()->user()
can return either the user og null
if no one is authenticated. It isn't aware that you might have already made sure that it's not possible to get to this portion of the code with out being authenticated.
You basically have to wrap this in a helper that will throw an error if the result is null, so that you can guaranty that the function will only ever return a user.
function authUser(): \Illuminate\Contracts\Auth\Authenticatable {
$authed = auth()->user();
if ($authed === null) {
abort(403);
}
return $authed;
}
Thank you for the explanation. Maybe my thread will help someone in the future. 🖖
We're seeing the following errors in a Blade template:
Here is how they are being output in the template:
In both cases, the
->id
column is non-nullable in the database schema, which we're utilizing via PHPStan with the following config option:In the examples above, there is an outer
@auth
directive conditional, but note that it occurs even without those. It also occurs with fields other than->id
. And although we have multiple guards, it also occurs withauth()->user()->id
(which utilizes the default guard, which isaccount
).Why is this the case? Is it an issue with Bladestan or are we doing something incorrectly?
Thank you!! We'd love to use your great extension.