use Encore\Admin\Widgets\Table; //必须写在控制器里
$grid->column(‘title‘, ‘标题‘)->expand(function ($model) { //这里要让哪个字段显示下拉,就写哪个字段,没什么要求
$comments = $model->comments()->take(10)->get()->map(function ($comment) { //$model->comments() 这个comments()是模型层里的模型关联方法名 take(10)获取十条
return $comment->only([‘id‘, ‘content‘, ‘created_at‘]); //要展示副表的什么字段就写什么字段
});
return new Table([‘ID‘, ‘内容‘, ‘发布时间‘], $comments->toArray());
});
原文:https://www.cnblogs.com/cffdn/p/13652645.html