column('id')->sortable(); $grid->column('name'); $grid->column('pid','父分类')->display(function () { /* @var EpisodesCategory $this*/ return $this->parent ?$this->parent->name : ''; }); $grid->column('created_at'); $grid->disableRowSelector(); $grid->disableViewButton(); }); } /** * Make a show builder. * * @param mixed $id * * @return Show */ protected function detail($id) { return Show::make($id, new EpisodesCategory(), function (Show $show) { $show->field('id'); $show->field('name'); $show->field('pid'); $show->field('path'); $show->field('sort'); $show->field('created_at'); $show->field('updated_at'); }); } /** * Make a form builder. * * @return Form */ protected function form() { return Form::make(new EpisodesCategory(), function (Form $form) { $categoryModel = app(\App\Models\EpisodesCategory::class); $options = $categoryModel::select(['id','name'])->where('pid',0)->get()->toArray(); array_unshift($options,['id' => 0, 'name' => '一级分类']); $options = array_column($options,'name','id'); $form->display('id'); $form->select('pid')->options($options); $form->text('name'); $form->disableViewButton(); $form->disableDeleteButton(); $form->disableListButton(); $form->disableEditingCheck(); $form->disableViewCheck(); $form->disableCreatingCheck(); }); } public function options(Request $request) { $q = $request->get('q'); $categoryModel = app(\App\Models\EpisodesCategory::class); return $categoryModel->where('name', 'like', "%$q%")->paginate(null, ['id', 'name as text']); } }