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

Add middleware using static method #2424

Merged
merged 4 commits into from May 7, 2023

Conversation

jnoordsij
Copy link
Contributor

Inspired by the addition of static using methods in the Laravel framework itself that allow creating middlewares with arguments in a static way (see laravel/framework#46362), this PR aims to add similar behavior to the middlewares in this package.

This allows a new syntax for adding the middlewares to routes and/or controllers, e.g. instead of 'permission:edit-articles|edit-news', one can now write PermissionMiddleware::using('edit-articles|edit-news') or even PermissionMiddleware::using(['edit-articles', 'edit-news']).

@parallels999
Copy link
Contributor

Also add usage info in docs
https://github.com/spatie/laravel-permission/blob/main/docs/basic-usage/middleware.md

@jnoordsij jnoordsij force-pushed the add-middleware-using-static-method branch from 594c409 to 6d64d6f Compare May 4, 2023 15:27
@jnoordsij
Copy link
Contributor Author

@parallels999 thanks for checking this! Added some bits to the docs to explain the new methods.

@drbyte
Copy link
Collaborator

drbyte commented May 7, 2023

I like the idea. Will review it in more detail soon...

@drbyte
Copy link
Collaborator

drbyte commented May 7, 2023

Thanks!

@drbyte drbyte merged commit 587ba9c into spatie:main May 7, 2023
20 checks passed
@jnoordsij jnoordsij deleted the add-middleware-using-static-method branch May 8, 2023 08:43
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.

None yet

3 participants