model()->orderBy('id', 'desc'); $grid->column('id')->sortable(); $grid->column('mch_no')->width('20%'); $grid->column('mch_name')->width('28%'); $grid->column('created_at'); $grid->column('updated_at')->sortable(); $grid->enableDialogCreate(); $grid->showQuickEditButton(); $grid->disableEditButton(); $grid->filter(function (Grid\Filter $filter) { $filter->equal('mch_no')->width(3); $filter->like('mch_name')->width(3); }); }); } /** * Make a show builder. * * @param mixed $id * * @return Show */ protected function detail($id) { return Show::make($id, new Merchant(), function (Show $show) { $show->field('id'); $show->field('mch_no'); $show->field('mch_name'); $show->field('created_at'); $show->field('updated_at'); }); } /** * Make a form builder. * * @return Form */ protected function form() { return Form::make(new Merchant(), function (Form $form) { $form->display('id'); if ($form->isCreating()) { $form->hidden('mch_no'); } else { $form->display('mch_no'); } $form->text('mch_name')->required(); $form->display('created_at'); $form->display('updated_at'); $form->saving(function (Form $form) { if ($form->isCreating()) { $form->mch_no = 'M'.time(); } }); $form->deleting(function (Form $form) { $data = $form->model()->toArray(); foreach ($data as $k => $v) { if (MchApp::where('mch_no', $v['mch_no'])->count() > 0) { return $form->response()->error("商户号{$v['mch_no']}已创建应用,请先删除应用"); } } }); }); } }