laravel-entrust-role-permission-panel icon indicating copy to clipboard operation
laravel-entrust-role-permission-panel copied to clipboard

Adding class disabled to buttons if user do not have access to that route

Open roulendz opened this issue 9 years ago • 2 comments

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 :)

roulendz avatar Apr 14 '15 08:04 roulendz

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.

florentsorel avatar Apr 14 '15 19:04 florentsorel

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';
    }
}

roulendz avatar Apr 15 '15 06:04 roulendz