laravel-entrust-role-permission-panel
laravel-entrust-role-permission-panel copied to clipboard
Adding class disabled to buttons if user do not have access to that route
Wanted to ask, what would be best way to impliment this?
now I am using helpers.php where I check what is route, and if route = request I return active
where I have
function set_active($path, $active = 'active')
{
return Request::is($path) ? $active : '' ;
}
how I would do here with user premmisions, if user do not have premission to access route then I want to return class="disabled"
Thanks for this awesome admin panel :)
May be something like that:
// $user => Auth::user() in your view
function isAuthorize($user) {
$permissions = Permission::all();
foreach($permissions as $permission)
{
return ($user->can($permission)) ?: 'disabled';
}
}
The code is similar to the AuthorizeMiddleware
For check routes, I need to update the middleware, for now it's working but is not the better way to do that I think. If you want check route, take a look to route filter.
Hmm, I do not why, but it all time returns disabled ;( I ended using this!
function check_premission($user_has_premissions)
{
if ( Auth::user()->can($user_has_premissions) == 1) {
return '';
} else {
return 'disabled';
}
}