Skip to content

[12.x] Add conditional return type hint for Route::middleware() method.#58699

Merged
taylorotwell merged 1 commit into
laravel:12.xfrom
marcreichel:improved-route-middleware-return-type
Feb 9, 2026
Merged

[12.x] Add conditional return type hint for Route::middleware() method.#58699
taylorotwell merged 1 commit into
laravel:12.xfrom
marcreichel:improved-route-middleware-return-type

Conversation

@marcreichel

Copy link
Copy Markdown
Contributor

This pull request adds a conditional return type to the Route::middleware() method based on the $middleware parameter, so PHPStan knows that the method returns the Route instance when $middleware is not null.

This is necessary for PHPStan level 7+ to be able to call Route::get('/')->middleware('auth')->name('home');, because otherwise PHPStan does not know if the Route or an array gets returned from the middleware method.

@taylorotwell taylorotwell merged commit 736f442 into laravel:12.x Feb 9, 2026
72 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants