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

Middleware #6

Closed
antonkomarev opened this issue Oct 16, 2015 · 2 comments
Closed

Middleware #6

antonkomarev opened this issue Oct 16, 2015 · 2 comments

Comments

@antonkomarev
Copy link
Contributor

What do you think about middleware?

Something like this for roles:

Route::get('post.create', [
    'as' => 'post.create',
    'middleware' => 'role:admin,editor',
    'uses' => 'PostController@create',
]);

And one more for an ability:

Route::get('post.create', [
    'as' => 'post.create',
    'middleware' => 'ability:create-post',
    'uses' => 'PostController@create',
]);
@JosephSilber
Copy link
Owner

I don't think having a middleware to check roles is a good idea. Roles are simply a way to give a user abilities. If you want all admins and editors to be able to create posts, give them that ability:

Bouncer::allow('admin')->to('create', Post::class);
Bouncer::allow('editor')->to('create', Post::class);

To check abilities in middleware, use Laravel's Authorize middleware.

@antonkomarev
Copy link
Contributor Author

wow thanks a lot! This link is exactly what I was looked for.

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

No branches or pull requests

2 participants