新增角色部门

This commit is contained in:
yanwenwu
2020-01-12 12:54:59 +08:00
parent 7c09bcf0cf
commit 1b7cc3fcf5
5 changed files with 108 additions and 2 deletions

View File

@@ -0,0 +1,57 @@
<?php
namespace catchAdmin\permissions\model;
trait HasDepartmentsTrait
{
/**
*
* @time 2019年12月08日
* @return mixed
*/
public function departments()
{
return $this->belongsToMany(Department::class, 'role_has_departments', 'department_id', 'role_id');
}
/**
*
* @time 2019年12月08日
* @return mixed
*/
public function getDepartments()
{
return $this->departments()->select();
}
/**
*
* @time 2019年12月08日
* @param array $departments
* @return mixed
*/
public function attachDepartments(array $departments)
{
if (empty($departments)) {
return true;
}
sort($departments);
return $this->departments()->attach($departments);
}
/**
*
* @time 2019年12月08日
* @param array $departments
* @return mixed
*/
public function detachDepartments(array $departments = [])
{
if (empty($departments)) {
return $this->departments()->detach();
}
return $this->departments()->detach($departments);
}
}

View File

@@ -6,13 +6,16 @@ use catcher\base\CatchModel;
class Roles extends CatchModel
{
use HasDepartmentsTrait;
protected $name = 'roles';
protected $field = [
'id', //
'role_name', // 角色名
'parent_id', // 父级ID
'creator_id',
'creator_id',
'data_range',
'description', // 角色备注
'created_at', // 创建时间
'updated_at', // 更新时间