BackpackForLaravel

Backpack for Laravel roles and permissions for the Users module

By May 27, 2021 No Comments

All details can be found here about the package.

A thing to note here is the package comes with the roles and permissions manageable out of the box. Check out this part for customizing on the user’s module.

We can use our own UsersCrudController as it is far more likely there will be some customization required. For whatever we require from their setup we can copy from their file.

For example: the following gives the manageable roles fields. Copied from their file as is.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
$this->crud->addFields([
      [
          'tab' => 'Roles',
        // two interconnected entities
        'label'             => trans('backpack::permissionmanager.user_role_permission'),
        'field_unique_name' => 'user_role_permission',
        'type'              => 'checklist_dependency',
        'name'              => ['roles', 'permissions'],
        'subfields'         => [
            'primary' => [
                'label'            => trans('backpack::permissionmanager.roles'),
                'name'             => 'roles', // the method that defines the relationship in your Model
                'entity'           => 'roles', // the method that defines the relationship in your Model
                'entity_secondary' => 'permissions', // the method that defines the relationship in your Model
                'attribute'        => 'name', // foreign key attribute that is shown to user
                'model'            => config('permission.models.role'), // foreign key model
                'pivot'            => true, // on create&update, do you need to add/delete pivot table entries?]
                'number_columns'   => 3, //can be 1,2,3,4,6
            ],
            'secondary' => [
                'label'          => ucfirst(trans('backpack::permissionmanager.permission_singular')),
                'name'           => 'permissions', // the method that defines the relationship in your Model
                'entity'         => 'permissions', // the method that defines the relationship in your Model
                'entity_primary' => 'roles', // the method that defines the relationship in your Model
                'attribute'      => 'name', // foreign key attribute that is shown to user
                'model'          => config('permission.models.permission'), // foreign key model
                'pivot'          => true, // on create&update, do you need to add/delete pivot table entries?]
                'number_columns' => 3, //can be 1,2,3,4,6
            ],
        ],
    ],
]);