视频教程 https://ke.qq.com/course/310428?taid=2118965065464988
1 安装
"zizaco/entrust": "5.2.x-dev"
composer update
php artisan make:seeder PermissionTableSeeder
databaseseedersDatabaseSeeder.php
<?php namespace DatabaseSeeders; use IlluminateDatabaseSeeder; use AppPermission; use AppUser; use AppRole; class PermissionTableSeeder extends Seeder { /** * Run the database seeds. * * @return void */ public function run() { DB::statement('SET FOREIGN_KEY_CHECKS = 0'); //清空权限相关的数据表 Permission::trunctate(); Role::trunctate(); User::trunctate(); DB::table('role_user')->delete(); DB::table('permission_role')->delete(); DB::statement('SET FOREIGN_KEY_CHECKS = 1'); //创建用户 $user = User::create([ 'name'=> 'ttt', 'email'=>'ttt@ttt.com', 'password'=>bcrypt('123456') ]); //创建角色 $admin = Role::create([ 'name'=>'admin', 'display_name'=>'管理员', 'description'=>'super admin role' ]); //创建权限 $manage_user = Permission::create([ 'name'=>'manage_user', 'display_name'=>'用户管理', 'description'=>'管理用户的权限' ]); //给角色赋予相应的权限 $admin = attachPermission($manage_user); //给用户赋予相应的角色 $user = attachRole($admin); } }