Paul Wright
Paul Wright

Reputation: 455

How to restrict access to delete in laravel using sentry

Using Laravel 4 and Sentry. I have a CRUD admin system that managers and admins can access. I want managers to have access to all CRUD operations except for DELETE. I know that I can add a line such as

@if (Sentry::check())

in my view to ensure the user is logged in, but don't know how to check that they are an admin.

I have the following filter

Route::filter('auth.admin', function()
{

$user = Sentry::getUser();
$admin = Sentry::findGroupByName('Admins');

if (!$user->inGroup($admin)) return Redirect::to('admin/login');
});

Upvotes: 0

Views: 234

Answers (1)

Jarek Tkaczyk
Jarek Tkaczyk

Reputation: 81187

Easy way:

if (Sentry::getUser()->isSuperUser())

// or
if (Sentry::hasPermission('superuser')) // or admin or whatever permission you want

or excplicitly:

if (Sentry::hasPermission('delete'))

Upvotes: 0

Related Questions