Skip to content

Resolve middleware aliases when inferring URL defaults - #295

Merged
joetannenbaum merged 4 commits into
laravel:mainfrom
lazerg:fix/issue-294-middleware-alias-url-defaults
Sep 9, 2026
Merged

Resolve middleware aliases when inferring URL defaults#295
joetannenbaum merged 4 commits into
laravel:mainfrom
lazerg:fix/issue-294-middleware-alias-url-defaults

Conversation

@lazerg

@lazerg lazerg commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Middleware aliases only reach the router when the HTTP kernel is resolved, and php artisan wayfinder:generate never resolves it. A group written as ->middleware(['auth', 'organization.user']) therefore hands Wayfinder the raw alias string, class_exists() on it fails, and whatever URL::defaults() the middleware sets gets missed, so the parameter stays required in the generated route.

The command now resolves the kernel before walking the routes. That sync overwrites middleware groups instead of merging into them, so anything a service provider already pushed onto a group is captured first and re-applied afterwards.

The test is phpunit rather than vitest because the workbench can't reproduce the bug: Testbench boots the HTTP kernel itself, so aliases are already synced there and a workbench route would pass with or without the fix.

Closes #294

@lazerg
lazerg force-pushed the fix/issue-294-middleware-alias-url-defaults branch from 6a6e09c to 2c6381c Compare August 7, 2026 00:09
@joetannenbaum

Copy link
Copy Markdown
Collaborator

Thank you!

@joetannenbaum
joetannenbaum merged commit dd454ed into laravel:main Sep 9, 2026
10 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.

Wayfinder does not infer URL defaults from middleware aliases

2 participants