You can do something like the following:
In app/filters.php, create a filter as follows.
Route::filter('permissions', function()
{
$name = Route::current()->getName();
$name = 'system' . ( ! empty($name) ? '.' : '') . $name;
if (!UserHelper::hasPermission($name)) {
App::abort(401, 'You are not authorized to access route '.$name);
}
});
You can apply the filter by putting a before filter on your route, e.g.
Route::group(array('before' => 'permissions'), function()
{
// routes
}
With this system, you could create permission groups like these:
Sentry::getGroupProvider()->create(array(
'id' => 1,
'name' => 'Super Administrators',
'permissions' => array(
'system' => 1,
),
));
Sentry::getGroupProvider()->create(array(
'id' => 2,
'name' => 'Administrators',
'permissions' => array(
'system.users' => 1,
'system.products' => 1,
'system.store' => 1,
'system.profile' => 1,
),
));
Sentry::getGroupProvider()->create(array(
'id' => $id++,
'name' => 'Managers',
'permissions' => array(
'system.products' => 1,
'system.store' => 1,
'system.profile' => 1,
),
));
So if a user has the system.products
permission, he'd be able to use every products route.
Now, for the part where you wish to show links to certain groups, you can do that with a helper like this:
public static function has($permission)
{
$all = [];
$parts = explode('.',$permission);
$permission = '';
foreach($parts as $part) {
$permission .= (!empty($permission) ? '.' : '') . $part;
$all[] = $permission;
}
return Sentry::check() and Sentry::getUser()->hasAnyAccess($all);
}
You'd simply pass the route name (e.g. system.products) to the function and it'll return whether the user has access to it. Source: https://laracasts.com/forum/conversation/post/2819