A
A
Alexander2016-03-17 08:43:39
Laravel
Alexander, 2016-03-17 08:43:39

In which file to create roles (RBAC)?

I want to install RBAC in my project. I'm using this library https://github.com/DynamicCodeNinja/RBAC
But I can't figure out where and in what file should I create roles?

use DCN\RBAC\Models\Role;

$adminRole = Role::create([
    'name' => 'Admin',
    'slug' => 'admin',
    'description' => '', // optional
    'parent_id' => NULL, // optional, set to NULL by default
]);

$moderatorRole = Role::create([
    'name' => 'Forum Moderator',
    'slug' => 'forum.moderator',
]);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Ukolov, 2016-03-17
@kentuck1213

where and in what file should I create roles?

Roles need to be created only once, and not every time the application starts, because they are just rows in the database.
Accordingly, you can create them as you like, just an example is given of how you can add them through the admin panel, for example. You can even execute this code php artisan tinker, there is no difference.

V
Vyacheslav Plisko, 2016-03-17
@AmdY

Better create a seed and pull it php artisan db:seed --class=RBACSeeder. Well, in general, all manipulations with the database through migrations and seeds.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question