94 lines
2.7 KiB
PHP
94 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use App\Admin\Repositories\ProductAttr;
|
|
use App\Models\ProductAttrGroup;
|
|
use Dcat\Admin\Admin;
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Http\Controllers\AdminController;
|
|
use Dcat\Admin\Show;
|
|
|
|
class ProductAttrController extends AdminController
|
|
{
|
|
/**
|
|
* Make a grid builder.
|
|
*
|
|
* @return Grid
|
|
*/
|
|
protected function grid()
|
|
{
|
|
$builder = ProductAttr::with('group');
|
|
return Grid::make($builder, function (Grid $grid) {
|
|
$grid->column('id')->sortable();
|
|
$grid->column('group.name');
|
|
$grid->column('name');
|
|
$grid->column('attrs')->label();
|
|
$grid->column('created_at')->sortable();
|
|
|
|
//排序
|
|
$grid->model()->orderBy('created_at', 'desc');
|
|
|
|
/** 操作 **/
|
|
//新增
|
|
if (Admin::user()->can('dcat.admin.product_attrs.create')) {
|
|
$grid->disableCreateButton(false);
|
|
$grid->enableDialogCreate();
|
|
}
|
|
|
|
//修改
|
|
$grid->showQuickEditButton(Admin::user()->can('dcat.admin.product_attrs.edit'));
|
|
//删除以及自定义操作
|
|
$grid->actions(function (Grid\Displayers\Actions $actions) {
|
|
$actions->disableDelete(Admin::user()->cannot('dcat.admin.product_attrs.destroy'));
|
|
});
|
|
|
|
/** 查询 **/
|
|
$grid->filter(function (Grid\Filter $filter) {
|
|
$filter->panel();
|
|
$filter->where('group', function ($query) {
|
|
$query->whereIn('group_id', ProductAttrGroup::descendantsAndSelf($this->input, ['id'])->pluck('id'));
|
|
}, __('product-attr.fields.group.name'))->select(ProductAttrGroup::selectOptions())->width(3);
|
|
$filter->like('name')->width(3);
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a show builder.
|
|
*
|
|
* @param mixed $id
|
|
*
|
|
* @return Show
|
|
*/
|
|
protected function detail($id)
|
|
{
|
|
return Show::make($id, new ProductAttr(), function (Show $show) {
|
|
$show->field('id');
|
|
$show->field('group_id');
|
|
$show->field('attrs');
|
|
$show->field('created_at');
|
|
$show->field('updated_at');
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a form builder.
|
|
*
|
|
* @return Form
|
|
*/
|
|
protected function form()
|
|
{
|
|
return Form::make(new ProductAttr(), function (Form $form) {
|
|
$form->display('id');
|
|
$form->select('group_id')->options(ProductAttrGroup::selectOptions());
|
|
$form->text('name')->required();
|
|
$form->list('attrs');
|
|
|
|
$form->display('created_at');
|
|
$form->display('updated_at');
|
|
});
|
|
}
|
|
}
|