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

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

藏色散人
Release: 2022-01-07 10:17:48
forward
3278 people have browsed it

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
Copy after login

2. Generate migration file

Execute the following command in composer

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

3. Generate configuration file

Execute the following command in composer

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

4. Migrate data

Execute the following command in composer

php artisan migrate
Copy after login

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
Copy after login

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);
Copy after login

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);
Copy after login

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!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template