1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- namespace App\Repositories\Models\Base;
- use Prettus\Repository\Contracts\Transformable;
- use Prettus\Repository\Traits\TransformableTrait;
- class Role extends \Spatie\Permission\Models\Role implements Transformable
- {
- use TransformableTrait;
- /**
- * @var string
- */
- protected $table = 'base_roles';
- protected $guarded = [];
- /**
- * The attributes excluded from the model's JSON form.
- *
- * @var array
- */
- protected $hidden = [];
- //全部权限
- const DATA_TYPE_ALL = 1;
- const DATA_MENU_ALL = 149;
- const DATA_MENU_SELF = 150;
- const DATA_MENU_EDIT_CHECK_STATUS = 151;
- //仅自己权限
- const DATA_TYPE_SELF = 2;
- //自定义
- const DATA_TYPE_CUSTOM = 3;
- // //自定义部门
- // const DATA_TYPE_DEPARTMENT = 3;
- // //自定义门店
- // const DATA_TYPE_SHOP = 4;
- // //自定义工厂
- // const DATA_TYPE_FACTORY = 5;
- /**
- * 检查关键字是否存在
- * @param $name
- * @param $ignore_id
- * @return bool
- */
- public static function checkNameIsUnique($name, $ignore_id = 0)
- {
- return self::query()->where('name', $name)->where('id', '<>', $ignore_id)->exists();
- }
- public function menus()
- {
- return $this->belongsToMany(Menu::class, 'base_roles_menus');
- }
- // public function departments()
- // {
- // return $this->belongsToMany(Department::class, 'base_roles_departments');
- // }
- // 自定义部门
- public function departments()
- {
- return $this->morphedByMany(Department::class, 'data', 'base_roles_data', 'role_id');
- }
- //自定义门店
- public function shops()
- {
- return $this->morphedByMany(Department::class, 'data', 'base_roles_data', 'role_id');
- }
- //自定义工厂
- public function factory()
- {
- return $this->morphedByMany(Department::class, 'data', 'base_roles_data', 'role_id');
- }
- }
|