<?php
declare (strict_types = 1);

namespace app\admin\model\v1;

use app\common\model\SysRoleBaseModel;
use think\model\concern\SoftDelete;

/**
 * 角色模型
 * @mixin \think\Model
 */
class SysRoleModel extends SysRoleBaseModel
{
    // 启用软删除
    use SoftDelete;
    // 软删除字段
    protected $deleteTime = 'deleted_at';

    // 关联权限
    public function authorities()
    {
        return $this->hasMany(SysRoleAuthorityModel::class, 'role_id', 'id');
    }

    // 角色名称搜索
    public function searchNameAttr($query, $value, $data)
    {
        if (empty($value)) {
            return;
        }
        $query->where('name', 'like', "%$value%");
    }
}
