Question

I have tried looking on the Cartalyst site for some documentation, but I can not find it any where. So, my question is... If I have a list of groups on the create view, say Admin, Moderator and User. How would I then automate the permissions for these groups?

So I would want admin to have create: 1, delete: 1 etc. Moderators can create, but not delete and a user couldn't do any of this.

On my create, I would have a dropdown where you can assign these groups to signed up users and that would automatically create the permissions for that user.

Could someone give me a quick overview on the easiest way of doing this? I expect there's some sort of function on Sentry which will help, but with Sentry being taken off the site, I can't seem to find the documentation.

Was it helpful?

Solution

First you need to create three groups (Admin, Moderator and Users) like you mentioned - here is the example for Admin group.

$group = Sentry::createGroup(array(
    'name'        => 'Admin',
    'permissions' => array(
        'admin' => 1,
        'create' => 1,
        'delete' => 1
    ),
));

For other groups, you can make changes in permissions array. You can get group permissions with -

$groupPermissions = $group->getPermissions();

There you go!

To assign users to specific groups, you can just added like below.

$adminGroup = Sentry::findGroupById(1);    
$user->addGroup($adminGroup);

All you need to do is to select any (created) group with dropdown to assign on user create. Or, you can simply assign user to the default group.

Anyway, You can find the Sentry documentation in Cartalyst/Sentry package inside vendor.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top