81 lines
1.8 KiB
PHP
81 lines
1.8 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace app\common\model;
|
||
|
|
|
||
|
|
use support\Model;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* resources 资源表:目录/菜单/权限
|
||
|
|
* @property integer $id 资源ID(主键)
|
||
|
|
* @property string $name 资源名称
|
||
|
|
* @property string $type 资源类型
|
||
|
|
* @property string $code 资源编码(权限标识)
|
||
|
|
* @property integer $parent_id 父资源ID
|
||
|
|
* @property string $url 路由 path 或 外链 URL
|
||
|
|
* @property string $icon 图标,仅目录/菜单有效
|
||
|
|
* @property string $open_type 菜单打开方式
|
||
|
|
* @property integer $sort 排序
|
||
|
|
* @property string $created_at
|
||
|
|
* @property string $updated_at
|
||
|
|
*/
|
||
|
|
class Resource extends Model
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* The connection name for the model.
|
||
|
|
*
|
||
|
|
* @var string|null
|
||
|
|
*/
|
||
|
|
protected $connection = 'mysql';
|
||
|
|
|
||
|
|
/**
|
||
|
|
* The table associated with the model.
|
||
|
|
*
|
||
|
|
* @var string
|
||
|
|
*/
|
||
|
|
protected $table = 'resources';
|
||
|
|
|
||
|
|
/**
|
||
|
|
* The primary key associated with the table.
|
||
|
|
*
|
||
|
|
* @var string
|
||
|
|
*/
|
||
|
|
protected $primaryKey = 'id';
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Indicates if the model should be timestamped.
|
||
|
|
*
|
||
|
|
* @var bool
|
||
|
|
*/
|
||
|
|
public $timestamps = true;
|
||
|
|
|
||
|
|
|
||
|
|
// 所属系统
|
||
|
|
public function system()
|
||
|
|
{
|
||
|
|
return $this->belongsTo(Systems::class, 'system_id', 'id');
|
||
|
|
}
|
||
|
|
|
||
|
|
// 拥有该资源的角色
|
||
|
|
public function roles()
|
||
|
|
{
|
||
|
|
return $this->belongsToMany(Role::class, 'role_resources', 'resource_id', 'role_id');
|
||
|
|
}
|
||
|
|
|
||
|
|
// 拥有该资源的用户(特殊补权)
|
||
|
|
public function users()
|
||
|
|
{
|
||
|
|
return $this->belongsToMany(User::class, 'user_resources', 'resource_id', 'user_id');
|
||
|
|
}
|
||
|
|
|
||
|
|
// 递归
|
||
|
|
public function parent()
|
||
|
|
{
|
||
|
|
return $this->belongsTo(self::class, 'parent_id');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function children()
|
||
|
|
{
|
||
|
|
return $this->hasMany(self::class, 'parent_id');
|
||
|
|
}
|
||
|
|
}
|