123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- namespace App\Admin\Controllers;
- use App\Models\ProductSpec;
- use App\Models\ProductSpecGroup;
- use Dcat\Admin\Form;
- use Dcat\Admin\Grid;
- use Dcat\Admin\Layout\Content;
- use Dcat\Admin\Show;
- use Dcat\Admin\Http\Controllers\AdminController;
- class ProductSpecController extends AdminController
- {
- protected $product_id;
- public function __construct()
- {
- $route = \request()->route();
- $this->product_id = $route->parameters['id'];
- }
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- return Grid::make(ProductSpec::with('group.product'), function (Grid $grid) {
- $grid->model()->orderByDesc('group_id')->orderByDesc('sort');
- $grid->column('id')->sortable();
- $grid->column('product','产品')->display(function (){
- return $this->group->product->name;
- })->label('info');
- $grid->column('group_id')->display(function (){
- return $this->group->name;
- })->label('success');
- $grid->column('name')->label('primary');
- $grid->column('sale_price')->editable();
- $grid->column('is_opened')->switch();
- $grid->column('sort')->editable();
- $grid->column('created_at');
- $url = admin_url('/product/'.$this->product_id.'/specGroup');
- $grid->tools('<a href="'.$url.'" class="btn btn-primary btn-outline" style="position: absolute;right: 118px;">
- <i class="fa fa-align-justify"></i> 规格组管理</a>');
- });
- }
- /**
- * Make a show builder.
- *
- * @param mixed $id
- *
- * @return Show
- */
- protected function detail($id)
- {
- return Show::make($id, new ProductSpec(), function (Show $show) {
- $show->field('id');
- $show->field('group_id');
- $show->field('name');
- $show->field('cover_img');
- $show->field('origin_price');
- $show->field('sale_price');
- $show->field('created_at');
- $show->field('updated_at');
- });
- }
- /**
- * Make a form builder.
- *
- * @return Form
- */
- protected function form()
- {
- return Form::make(new ProductSpec(), function (Form $form) {
- $form->display('id');
- $cates = ProductSpecGroup::select(['id','name'])->where('is_opened',1)->get()->toArray();
- $form->radio('group_id')
- ->options(array_column($cates,'name','id'))
- ->required();
- $form->text('name')->required();
- $form->decimal('sale_price')->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();
- });
- }
- }
|