-
Notifications
You must be signed in to change notification settings - Fork 59
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 ability to filter through menu items #26
Comments
I should add a way to filter menu items, which would cover this use case. In the mean time, you're able to assign any additional meta data you may have to your menu items through the |
Just pushed v1.0.3, which has the ability to filter menu items. Here's a simple usage example: Menu::make('test', function($menu) {
$menu->add('Google', 'http://google.com')->data('permissions', ['view_google']);
})->filter(function($item) {
dd($item->data('permissions'));
// Simply check if your users can perform the defined permissions, and return a boolean.
// If you're using the Caffeinated Shinobi package, the usage would simply be:
//
// return Auth::user()->can($item->data('permissions'));
}); |
Could this work with middleware? |
To be honest, I don't know. Haven't tried or messed around with creating middleware myself. If it helps any, the |
Okay, that actually helps. I'm using Entrust, but to be fair all I need is simple permissions which might send me over to Shinobi. I might be better off moving my menu to a custom composer that I can send permissions to or something like that. Custom Middleware https://laracasts.com/discuss/channels/general-discussion/check-if-user-has-admin-role-1 |
I'm currently trying to have the builder check if each item will give access before it's added to the tree.
(ACL-based, defined on the routes)
Basically what I'm trying to do, is filter out items that are not accessible to the user.
(If a root item is not allowed via ACL, then all underlying items are also prohibited)
Initially I was looking into overriding Builder::add() to match the given URL to the routes, and then checking the route if it matches for access. But If an item is not allowed, I'm not able to return nothing from add().
Am I looking into the wrong direction? ;-)
The text was updated successfully, but these errors were encountered: