PHPStan and Laravel Breeze
Published
By James Clark
If you are using Laravel Breeze along-side PHPStan, you are likely seeing an error in the Http/Controllers/Auth/VerifyEmailController.php
controller on line 23.
Parameter #1 $user of class Illuminate\Auth\Events\Verified constructor expects Illuminate\Contracts\Auth\MustVerifyEmail, App\Models\User|null given.
There are numerous ways to approach fixing this, but the quickest and easiest is to simply tell PHPStan to ignore it with a
/** @phpstan-ignore-next-line */
immediately before
event(new Verified($request->user()));
The full file with this change in place:
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Auth\Events\Verified;
use Illuminate\Foundation\Auth\EmailVerificationRequest;
use Illuminate\Http\RedirectResponse;
class VerifyEmailController extends Controller
{
/**
* Mark the authenticated user's email address as verified.
*/
public function __invoke(EmailVerificationRequest $request): RedirectResponse
{
if ($request->user()->hasVerifiedEmail()) {
return redirect()->intended(RouteServiceProvider::HOME.'?verified=1');
}
if ($request->user()->markEmailAsVerified()) {
+ /** @phpstan-ignore-next-line */
event(new Verified($request->user()));
}
return redirect()->intended(RouteServiceProvider::HOME.'?verified=1');
}
}