Пример #1
0
 /**
  * 创建或更新Role
  *
  * @param  Douyasi\Models\Role $role
  * @param  array $inputs
  * @return Douyasi\Models\Role
  */
 private function saveRole($role, $inputs)
 {
     $role->name = e($inputs['name']);
     $role->display_name = e($inputs['display_name']);
     if (array_key_exists('description', $inputs)) {
         $role->description = e($inputs['description']);
     }
     if ($role->save()) {
         if (array_key_exists('permissions', $inputs)) {
             $permissions = $inputs['permissions'];
             //这里提交的为数组
             if (is_array($permissions) && $permissions) {
                 $role->perms()->sync($permissions);
                 //同步角色权限
             }
         } else {
             $role->perms()->sync([]);
         }
     }
     return $role;
 }
Пример #2
0
 /**
  * 获取所有角色(用户组)
  *
  * @return Illuminate\Support\Collection
  */
 public function role()
 {
     return $roles = $this->role->all();
 }