-
Notifications
You must be signed in to change notification settings - Fork 11.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't specify middleware within a controller class as described in the documentation #54181
Comments
Hey there, thanks for reporting this issue. We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as one separate commit on the main/master branch and share the repository here? Please make sure that you have the latest version of the Laravel installer in order to run this command. Please also make sure you have both Git & the GitHub CLI tool properly set up.
Do not amend and create a separate commit with your custom changes. After you've posted the repository, we'll try to reproduce the issue. Thanks! |
I can confirm this. This is caused because the definition of the controller in the tests missed This is the link to the repo to reproduce the issue I opened a PR to fix the test. I'm open to fixing this if you give me the green light. Edit: I took the liberty of fixing the entire issue, including the test, to ensure the problem is fully resolved. I understand this was done without prior approval, so I welcome any feedback or further suggestions. Please let me know if there's anything that needs adjustment! |
In Laravel 11, |
`Illuminate\Routing\Controller`. fixes laravel/framework#54181 Signed-off-by: Mior Muhammad Zaki <[email protected]>
Hmmm, you' right! The app I'm working on is a L10 upgraded to L11 and this modification wasn't applied. |
Laravel Version
11.37
PHP Version
8.2
Database Driver & Version
No response
Description
The documentation states:
But this code is purely not valid because we can't use the
HasMiddleware
trait on theController
class.The
Controller
'smiddleware
method is not static:framework/src/Illuminate/Routing/Controller.php
Line 23 in 5f0abfd
While the trait's method is:
framework/src/Illuminate/Routing/Controllers/HasMiddleware.php
Line 12 in 5f0abfd
The resulting error is this one:
Steps To Reproduce
Create a blank project
Create a controller
Use the HasMiddleware trait on the controller's class
The text was updated successfully, but these errors were encountered: