Skip to content
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

[10.x] Fix the issue of HasMiddleware compatibility #51748

Closed

Conversation

mahmoudmohamedramadan
Copy link
Contributor

By chance, I have read this section. So, I realized it might be why @taylorotwell closed this PR #51058.

@mahmoudmohamedramadan mahmoudmohamedramadan changed the title Fix the issue of HasMiddleware compatibility [10.x] Fix the issue of HasMiddleware compatibility Jun 8, 2024
@rodrigopedra
Copy link
Contributor

Changes in interfaces should be pushed to the master branch.

I see your previous PR was sent to master, but the reality is that it takes a while to understand what this PR is improving. (I am not a native English speaker, so take my comment with a grain of salt).

The problem I see is that new Laravel apps, created from version 11, have a plain class as their base controller, aimed just to share common code between controller classes, and it does no longer inherits from the Illuminate\Routing\Controller class.

Thus, the Illuminate\Routing\Controller@middleware method does not conflict with the Illuminate\Routing\HasMiddleware@middleware method definition.

https://github.com/laravel/laravel/blob/3b3f9f13faab1753e7b7cad6a0e7098e54c8199f/app/Http/Controllers/Controller.php#L1-L8

The scenario you describe, on PR #51058, applies to apps being migrated to Laravel 11.

For those, they can keep declaring middleware on their constructor, if their base controller still extends the Illuminate\Routing\Controller class, and skip implementing the Illuminate\Routing\HasMiddleware interface. So, no conflicts between the interface and the base class would happen.

Maybe proposing marking Illuminate\Routing\Controller as deprecated or internal on the next release, could be a better middle ground instead. So people migrating existing apps can adapt to the new proposed methodology for defining middleware within their controllers.

@mahmoudmohamedramadan
Copy link
Contributor Author

@rodrigopedra Also, it's not my native language :)

My PR intends to solve the issue that appears in that comment.

You say that the problem does not exist in Laravel v.11 Apps and it is not completely true because what if someone makes the plain class extends Illuminate\Routing\Controller and then implements the Illuminate\Routing\HasMiddleware, the error will be presented again!

The PR targets the versions lower than v.11 in a large percentage because the newly created controllers extend Illuminate\Routing\Controller by default which fires the problem if they implement the Illuminate\Routing\HasMiddleware.

So, the problem will exist in all versions, therefore, I am surprised that Taylor closed the PR but, it may mark the Illuminate\Routing\Controller deprecated as you said.

@taylorotwell
Copy link
Member

They aren't meant to be used together. If you extend base controller you don't use HasMiddleware.

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.

3 participants