2026-03-09 10:12:26 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Model;
|
|
|
|
|
|
2026-03-09 14:11:38 +08:00
|
|
|
use Hyperf\Database\Model\Relations\BelongsToMany;
|
2026-03-09 10:12:26 +08:00
|
|
|
use Hyperf\Database\Model\Relations\HasMany;
|
|
|
|
|
use Hyperf\DbConnection\Model\Model;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @property int $id
|
|
|
|
|
* @property string $name
|
|
|
|
|
* @property string $label
|
|
|
|
|
* @property string $description
|
|
|
|
|
* @property \Carbon\Carbon $created_at
|
|
|
|
|
* @property \Carbon\Carbon $updated_at
|
|
|
|
|
*/
|
|
|
|
|
class Role extends Model
|
|
|
|
|
{
|
|
|
|
|
protected ?string $table = 'roles';
|
|
|
|
|
|
|
|
|
|
protected array $fillable = [
|
|
|
|
|
'name',
|
|
|
|
|
'label',
|
|
|
|
|
'description',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected array $casts = [
|
|
|
|
|
'id' => 'integer',
|
|
|
|
|
'created_at' => 'datetime',
|
|
|
|
|
'updated_at' => 'datetime',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 角色下的用户
|
|
|
|
|
*/
|
|
|
|
|
public function users(): HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(User::class, 'role_id');
|
|
|
|
|
}
|
2026-03-09 14:11:38 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 角色授权的路由分组
|
|
|
|
|
*/
|
|
|
|
|
public function routeGroups(): BelongsToMany
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(RouteGroup::class, 'role_route_groups', 'role_id', 'group_id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 角色的路由覆盖规则
|
|
|
|
|
*/
|
|
|
|
|
public function routeOverrides(): HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(RoleRouteOverride::class, 'role_id');
|
|
|
|
|
}
|
2026-03-09 10:12:26 +08:00
|
|
|
}
|