Weave Code
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

After Installation

Configuration Files

In your config/laratrust.php file you will find all the package configurations that you can customize.

Teams Feature

If you want to use the teams feature that allows you to attach roles and permissions to an user depending on a team, you must change the use_teams key value to true in your config/laratrust.php file. Then follow the teams configuration guide.

Multiple User Models

In the config/laratrust.php file you will find an user_models array, it contains the information about the multiple user models and the name of the relationships inside the Role and Permission models. For example:

'user_models' => [
    'users' => 'App\User',
],

::: tip NOTE The value of the key in the key => value pair defines the name of the relationship inside the Role and Permission models. :::

It means that there is only one user model using Laratrust, and the relationship with the Role and Permission models is going to be called like this:

$role->users;
$role->users();

::: tip NOTE Inside the role_user and permission_user tables the user_type column will be set with the user's fully qualified class name, as the polymorphic relations describe it in Laravel docs.

If you want to use the MorphMap feature just change the use_morph_map value to true in Laratrust's configuration file. :::

Automatic setup (Recommended)

If you want to let laratrust to setup by itself, just run the following command

php artisan laratrust:setup

::: warning If Laravel does not recognize this command, the Laratrust service provider hasn't been registered. Check providers array in config/app.php and try clearing your configuration cache

php artisan config:clear

:::

This command will generate the migrations, create the Role and Permission models (if you are using the teams feature it will also create a Team model) and will add the trait to the configured user models.

::: tip NOTE The user trait will be added to the models configured in the config/laratrust.php file. :::

And then do not forget to run

composer dump-autoload

::: tip IMPORTANT If you did the steps above you are done with the configuration, if not, please read and follow the whole configuration process :::

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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport