/** * Execute the console command. * * @return mixed */ public function handle() { $this->call('migrate'); $role = Role::create(['name' => 'admin', 'display_name' => '超级管理员']); $permission = Permission::create(['name' => 'admin', 'display_name' => '超级管理员权限']); $user = Admin::create(['name' => '超级管理员', 'email' => env('ADMIN_EMAIL', '*****@*****.**'), 'password' => bcrypt(env('ADMIN_PASSWORD', 'admin'))]); $role->attachPermission($permission); $user->attachRole($role); $this->info('Forone initialized!'); }
/** * Create a new user instance after a valid registration. * * @param array $data * @return User */ public function create(array $data) { return Admin::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]); }
/** * 分配角色 */ public function assignRole(Request $request) { $user = Admin::find($request->get('id')); $roles = $request->except(['_token', 'id']); $user->detachRoles($user->roles()->get()); foreach ($roles as $name => $status) { $role = Role::whereName($name)->first(); if ($status == 'on') { $user->attachRole($role); } } return $this->toIndex('角色分配成功'); }