study-api-v2/app/Models/System/SystemMenu.php
hx a621de91ff feat(system): 添加系统菜单、角色菜单关联和用户角色关联功能- 新增系统菜单模型、控制器、请求验证和业务逻辑
- 新增角色菜单关联模型、控制器、请求验证和业务逻辑
- 新增用户角色关联模型、控制器、请求验证和业务逻辑
- 更新系统角色模型,增加与用户和菜单的关联
- 更新用户模型,增加与角色的关联和相关方法
- 在路由文件中添加新功能的路由定义
2025-07-15 01:14:15 +08:00

101 lines
2.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Models\System;
use App\Models\BaseModel;
/**
* 系统菜单模型
*
* @property int $id 菜单ID
* @property string $name 菜单名称
* @property int $parent_id 父菜单ID
* @property int $type 菜单类型1目录 2菜单 3按钮
* @property string $path 路由地址
* @property string $icon 菜单图标
* @property string $component 组件路径
* @property string $component_name 组件名
* @property int $status 菜单状态0正常 1停用
* @property int $visible 显示状态0显示 1隐藏
* @property int $keep_alive 是否缓存0缓存 1不缓存
* @property int $always_show 是否总是显示根路由
* @property string $creator 创建者
* @property string $create_time 创建时间
* @property string $updater 更新者
* @property string $update_time 更新时间
* @property int $deleted 删除标识
* @property int $tenant_id 租户ID
* @property int $sort 显示顺序
*/
class SystemMenu extends BaseModel
{
protected $table = 'system_menu';
protected $fillable = [
'name',
'parent_id',
'type',
'path',
'icon',
'component',
'component_name',
'status',
'visible',
'keep_alive',
'always_show',
'sort',
];
protected $hidden = [
'deleted',
];
protected $casts = [
'id' => 'integer',
'parent_id' => 'integer',
'type' => 'integer',
'status' => 'integer',
'visible' => 'integer',
'keep_alive' => 'integer',
'always_show' => 'integer',
'sort' => 'integer',
'creator' => 'integer',
'updater' => 'integer',
'deleted' => 'integer',
'tenant_id' => 'integer',
'create_time' => 'datetime',
'update_time' => 'datetime',
];
/**
* 父级菜单
*/
public function parent()
{
return $this->belongsTo(SystemMenu::class, 'parent_id');
}
/**
* 子级菜单
*/
public function children()
{
return $this->hasMany(SystemMenu::class, 'parent_id');
}
/**
* 菜单角色关联
*/
public function roleMenus()
{
return $this->hasMany(SystemRoleMenu::class, 'menu_id');
}
/**
* 菜单的角色(多对多)
*/
public function roles()
{
return $this->belongsToMany(SystemRole::class, 'system_role_menu', 'menu_id', 'role_id');
}
}