Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laratrust Laravel Package

santigarcor/laratrust

Laratrust adds role and permission management to Laravel with support for multiple user models, teams, guards, caching, events, middleware, gates/policies, and an optional admin panel for managing roles and permissions.

View on GitHub
Deep Wiki
Context7

Seeder

Laratrust comes with a database seeder, this seeder helps you fill the permissions for each role depending on the module, and creates one user for each role.

::: tip NOTE Laratrust now accepts multiple user models so the seeder is going to work with the first user model inside the user_models array. :::

::: tip NOTE Laratrust now has teams feature, the seeder doesn't support it. :::

To generate the seeder you have to run

php artisan laratrust:seeder

and

composer dump-autoload

And in the database/seeds/DatabaseSeeder.php file you have to add this to the run method:

$this->call(LaratrustSeeder::class);

::: tip NOTE If you have not run php artisan vendor:publish --tag="laratrust" you should run it in order to customize the roles, modules and permissions in each case. :::

Your config/laratrust_seeder.php file looks like this:

return [
    'role_structure' => [
        'superadministrator' => [
            'users' => 'c,r,u,d',
            'acl' => 'c,r,u,d',
            'profile' => 'r,u'
        ],
        'administrator' => [
            'users' => 'c,r,u,d',
            'profile' => 'r,u'
        ],
        'user' => [
                'profile' => 'r,u'
        ],
    ],
    'permission_structure' => [
        'cru_user' => [
            'profile' => 'c,r,u'
        ],
    ],
    ...
];

To understand the role_structure you must know:

  • The first level is the roles.
  • The second level is the modules.
  • The second level assignments are the permissions.

With that in mind, you should arrange your roles, modules and permissions like this:

return [
    'role_structure' => [
        'role' => [
            'module' => 'permissions',
        ],
    ]
];

To understand the permission_structure you must know:

  • The first level is the users.
  • The second level is the modules.
  • The second level assignments are the permissions.

With that in mind, you should arrange your users, modules and permissions like this:

return [
    'permission_structure' => [
        'user' => [
            'module' => 'permissions',
        ],
    ]
];

Permissions

In case that you do not want to use the c,r,u,d permissions, in the config/laratrust_seeder.php there the permissions_map where you can change the permissions mapping.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
novasa/laravel-language-center
opencage/geocode
adolfoholzer/parameters
livenetworks/ln-starter
shitoudev/permissionmanager
johannesclimacus/laravel-tui
hocvt/seotools
vitalybaev/sypexgeo
amphibee/themosis-ignition
gito-me/fast-excel
frankyso/laravel-ipaymu
geolize-studio/laravel-chile
boomerangui/chat
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core