修复后台 /admin/cleanup/plan-contents?page=1 页面中"所属计划"和"模型"列显示错误的问题。
在Cleanup模块的计划内容管理页面中,发现以下显示问题:
通过检查代码和数据库,发现问题原因:
CleanupPlanContentRepository 没有预加载关联关系plan.plan_name 但没有预加载 plan 关联.switch() 方法显示布尔字段.using() + .label() 方式显示修改 app/Module/Cleanup/Repositories/CleanupPlanContentRepository.php:
/**
* 构造函数 - 设置关联关系
*/
public function __construct()
{
// 设置需要预加载的关联关系
parent::__construct(['plan']);
}
修改 app/Module/Cleanup/AdminControllers/CleanupPlanContentController.php:
// 状态
$grid->column('is_enabled', '启用状态')->using([1 => '启用', 0 => '禁用'])->label([
1 => 'success',
0 => 'danger',
])->sortable();
$grid->column('backup_enabled', '备份启用')->using([1 => '启用', 0 => '禁用'])->label([
1 => 'success',
0 => 'danger',
])->sortable();
修复后的页面显示效果:
在Dcat Admin中使用关联查询时,需要在Repository中预加载关联关系:
// 在构造函数中设置关联关系
parent::__construct(['relation1', 'relation2']);
对于布尔字段,推荐使用 using() + label() 而不是 switch():
// 推荐方式
$grid->column('field')->using([1 => '启用', 0 => '禁用'])->label([
1 => 'success',
0 => 'danger',
]);
// 避免在列表页使用
$grid->column('field')->switch(); // 可能不显示
修复Cleanup模块后台计划内容列表显示问题
- 修复CleanupPlanContentRepository缺少关联关系预加载的问题
- 修复所属计划列显示为空的问题
- 修复启用状态和备份启用列显示为空的问题
- 将switch字段改为using+label显示方式,确保正确显示状态
用户反馈希望显示完整的类名(包含命名空间),而不是简化的类名。
修改内容:
class_basename($value) 函数调用$value修改前:显示 AdminActionlog
修改后:显示 App\Module\System\Models\AdminActionlog
app/Module/Cleanup/Repositories/CleanupPlanContentRepository.phpapp/Module/Cleanup/AdminControllers/CleanupPlanContentController.php