Get the App
SLTechnology News&Howtos  ›  Development  › 

How to add user Rights Management in laravel8.5

Shulou Source: shulou.com Published: 2022-06-02 04:06:54 09月20日 Update

This article mainly explains "laravel8.5 how to add user rights management," interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let Xiaobian take you to learn "laravel8.5 how to add user rights management"!

1. Use composer to install laravel-permission package

Composer executes the following command

composer require spatie/laravel-permission

2. Generate migration file

Composer executes the following command

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

3. Generate configuration files

Composer executes the following command

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

4. Migrating data

Composer executes the following command

php artisan migrate

After execution, I don't know what other people are like. My appearance is reported incorrectly. 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 Baidu a big circle, according to the change or not, look at the migration file I suddenly realized, database\migrations\2022_01_06_041301_create_permission_tables.php(command generated migration file) this inside several fields of the string type length, manually set it, mine is mysql8.0, I saw this realization at that time;

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

Then change the string type of the migration file to such a full, no error will be reported, and then 5 tables will be generated in the database. The migrations table seems useless and can be deleted.

$table->string('name','125'); // For MySQL 8.0 use string ('name ', 125); At this point, I believe that everyone has a deeper understanding of "laravel8.5 how to add user rights management", may wish to actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

Tags: Commands files generation permissions users management content characters strings data types learning wrong practical deeper interests fields practical practical manual Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Linux Shulou Technology Huawei Xiaomi