Not sure why it happens in php 8, but try this
if (auth()->check() && auth()->user()->can('view', Model::class)) { ...
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello All,
I have an issue where a test will infinite loop.
This test isdisabling all authentication middleware via withoutMiddleware() and followingRedirects().
The custom implementation
$this->withoutMiddleware([
\App\Http\Middleware\Authenticate::class,
\App\Http\Middleware\RedirectIfAuthenticated::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Auth\Middleware\Authorize::class,
]);
It seems that the test is now instant looping and throwing the following error in the logs:
Error with message: Call to a member function can() on null. .
The null is thrown on the following line of code:
if (auth()->user()->can('view', Model::class)) { ...
I wonder why I get this issue on PHP 8.0, while on PHP 7.4 this exception was not thrown at all (as auth()->user() was also null on php 7.4).
I hope someone can help me out!
Kind regards.
Not sure why it happens in php 8, but try this
if (auth()->check() && auth()->user()->can('view', Model::class)) { ...
Please or to participate in this conversation.