Skip to content

Conversation

avosalmon
Copy link
Contributor

Route::middleware method's PHPDoc says it accepts null. However, it throws the following exception when null is passed as middleware.

CleanShot 2025-10-18 at 21 30 57

Because of this, when we conditionally apply a middleware, we need to fallback to an empty array.

Route::middleware(when(app()->isProduction(), MyMiddleware::class, []))

This PR fixes the issue by filtering out falsy values before registering middlewares.

@github-actions
Copy link

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@avosalmon avosalmon changed the title Filter out invalid middleware values [12.x] Update Route::middleware to accept null Oct 18, 2025
@avosalmon avosalmon force-pushed the null-middleware branch 3 times, most recently from f5551bc to 9362c02 Compare October 18, 2025 13:09
@avosalmon avosalmon marked this pull request as ready for review October 18, 2025 13:54
@taylorotwell taylorotwell merged commit 500c837 into laravel:12.x Oct 18, 2025
129 of 133 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