belongsToMany(Role::class, 'user_roles', 'user_id', 'role_id'); } // 用户直接拥有的资源(用于特殊补权) public function resources() { return $this->belongsToMany(Resource::class, 'user_resources', 'user_id', 'resource_id')->orderBy('sort', 'asc'); } // 用户可访问的系统 public function systems() { return $this->belongsToMany(Systems::class, 'user_systems', 'user_id', 'system_id'); } // 账号查询的作用域 public function scopeByAccount($query, $account) { return $query->where('sn', $account) ->orWhere('mobile', $account) ->orWhere('email', $account); } }