弹窗-详情
g r i d − > c o l u m n ( ′ t i t l e ′ , ′ 标 题 ′ ) − > m o d a l ( ′ 最 新 评 论 ′ , f u n c t i o n ( grid->column('title', '标题')->modal('最新评论', function ( grid−>column(′title′,′标题′)−>modal(′最新评论′,function(model) {
$comments = $model->comments()->take(10)->get()->map(function ($comment) {
return $comment->only(['id', 'content', 'created_at']);
});
return new Table(['ID', '内容', '发布时间'], $comments->toArray());
});
弹窗-审核
php artisan admin:action Post\Audit --grid-row --name=“审核”
class Audit extends RowAction
{
public $name = ‘审核通过’;
public function handle(Model $model,Request $request)
{
$subject = $request->get('subject');
$reason = $request->get('reason');
$model->setAttribute("subject",$subject);
$model->setAttribute("reason",$reason);
$model->save();
return $this->response()->success('Success message.')->refresh();
}
public function form()
{
$subjectList = [
1 => '科目一',
2 => '科目二',
3 => '科目三',
];
$this->select('subject', '所述科目')->options($subjectList);
$this->textarea('reason', '备注')->rules('required');
}
}
统计
如果某一列字段的值为数字,并且需要统计之后显示在表格的底部,可以用下面的方法。
$grid->column(‘quantity’, ‘数量’)->totalRow();
$grid->column(‘amount’, ‘金额’)->totalRow();
如果你想改变统计行的显示样式,可以通过传入一个匿名函数来修改它:
g r i d − > c o l u m n ( ′ a m o u n t ′ , ′ 金 额 ′ ) − > t o t a l R o w ( f u n c t i o n ( grid->column('amount', '金额')->totalRow(function ( grid−>column(′amount′,′金额′)−>totalRow(function(amount) {
return "<span class='text-danger text-bold'><i class='fa fa-yen'></i> {$amount} 元</span>"
});