1, 'vip' => 2]; protected $type = 1; public function __construct() { $route = \request()->route(); $arr = explode("/",$route->uri); $this->type = $this->types[$arr[2]]??1; } /** * Make a grid builder. * * @return Grid */ protected function grid() { return Grid::make(new ProductHot(), function (Grid $grid) { $grid->model()->orderByDesc('sort'); $grid->model()->where('type', $this->type); $grid->column('id')->sortable(); $grid->column('cover_img')->image('',80); $grid->column('product_id')->display(function (){ $this->products = $this->product_id; $names = $this->products->pluck('name')->toArray(); return implode('、',$names); }); $grid->column('is_opened')->switch(); $grid->column('sort')->editable(); $grid->column('created_at'); // $grid->filter(function (Grid\Filter $filter) { // $filter->equal('id'); // // }); $grid->disableViewButton(); }); } /** * Make a show builder. * * @param mixed $id * * @return Show */ protected function detail($id) { return Show::make($id, new ProductHot(), function (Show $show) { $show->field('id'); $show->field('type'); $show->field('product_id'); $show->field('sort'); $show->field('is_opened'); $show->field('created_at'); $show->field('updated_at'); }); } /** * Make a form builder. * * @return Form */ protected function form() { return Form::make(new ProductHot(), function (Form $form) { $form->display('id'); $form->hidden('type')->value($this->type); $cates = Product::select(['id','name'])->where('is_opened',1)->get()->toArray(); $form->multipleSelect('product_id') ->options(array_column($cates,'name','id')) ->required(); $form->image('cover_img','爆款图片(宽高比 1.34:1)')->saveFullUrl() ->uniqueName()->autoUpload() ->autoSave(false) ->removable(false) ->width(4) ->required(); $form->radio('is_opened')->options(config('global.bool_status'))->default(1); $form->number('sort'); $form->disableViewButton(); $form->disableDeleteButton(); $form->disableListButton(); $form->disableEditingCheck(); $form->disableViewCheck(); $form->disableCreatingCheck(); }); } }