Home  >  Article  >  PHP Framework  >  Detailed explanation of how to add user rights management in laravel8.5

Detailed explanation of how to add user rights management in laravel8.5

藏色散人
藏色散人forward
2022-01-06 15:25:553275browse

The following tutorial column from Laravel will introduce to you how to use laravel-permission to add user permission management in laravel8.5. I hope it will be helpful to everyone!

1. Use composer to install the laravel-permission package

Execute the following commands in composer

composer require spatie/laravel-permission

2. Generate migration file

Execute the following command in composer

php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider" --tag="migrations"

3. Generate configuration file

Execute the following command in composer

php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider" --tag="config"

4. Migrate data

Execute the following command in composer

php artisan migrate

Execute Finally, I don’t know what other people are like. Mine reported an error, and the prompt is as follows

 SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes

Then I searched around on Baidu, and it still wasn’t right after I tried to change it. After looking at the migration file, I realized it and changed the database\ The string type lengths of several fields in migrations\2022_01_06_041301_create_permission_tables.php (the migration file generated by the command) can be set manually. Mine is mysql8.0. I realized this when I saw it;

$table->string('name');    // For MySQL 8.0 use string('name', 125);

Then change all the string types of the migration file to this, and no errors will be reported, and then 5 tables will be generated in the database. This migrations table seems useless and can be deleted;

$table->string('name','125');       // For MySQL 8.0 use string('name', 125);

The installation of laravel-permission is complete here. I don’t know how to use it later. If anyone knows how to use it, please give me some advice. Or I can spend money to ask for advice. Please leave your Penguin account. Later, we will improve the installation and use of this permission management;

The latest five Laravel video tutorials (recommended)

The above is the detailed content of Detailed explanation of how to add user rights management in laravel8.5. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete