BaseProductController.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Repositories\BaseProduct;
  4. use Dcat\Admin\Form;
  5. use Dcat\Admin\Grid;
  6. use Dcat\Admin\Show;
  7. use Dcat\Admin\Http\Controllers\AdminController;
  8. use App\Models\BaseProductCategory;
  9. class BaseProductController extends AdminController
  10. {
  11. /**
  12. * Make a grid builder.
  13. *
  14. * @return Grid
  15. */
  16. protected function grid()
  17. {
  18. return Grid::make(BaseProduct::with('baseProductCategory'), function (Grid $grid) {
  19. $grid->column('id','ID')->sortable();
  20. $grid->column('title');
  21. $grid->column('sku');
  22. $grid->column('baseProductCategory.name','Category Name');
  23. $grid->column('publish_date');
  24. $grid->column('order')->orderable();
  25. $grid->column('enabled')->switch();
  26. $grid->column('created_at');
  27. $grid->column('updated_at')->sortable();
  28. // 筛选
  29. $grid->filter(function (Grid\Filter $filter) {
  30. $filter->equal('sku');
  31. $filter->like('title');
  32. $filter->equal('category_id','Category')->select(BaseProductCategory::selectOptions());
  33. });
  34. //排序
  35. $grid->model()->orderBy("order",'asc')->orderBy('id', 'desc');
  36. // 禁用查看按钮
  37. $grid->disableViewButton();
  38. $grid->showQuickEditButton();
  39. $grid->enableDialogCreate();
  40. $grid->disableEditButton();
  41. });
  42. }
  43. /**
  44. * Make a show builder.
  45. *
  46. * @param mixed $id
  47. *
  48. * @return Show
  49. */
  50. protected function detail($id)
  51. {
  52. return Show::make($id, new BaseProduct(), function (Show $show) {
  53. $show->field('id');
  54. $show->field('title');
  55. $show->field('keywords');
  56. $show->field('description');
  57. $show->field('sku');
  58. $show->field('baseProductCategory.name','Category Name');
  59. $show->field('publish_date');
  60. $show->field('order');
  61. $show->field('enabled');
  62. $show->field('content');
  63. $show->field('parameters');
  64. $show->field('created_at');
  65. $show->field('updated_at');
  66. });
  67. }
  68. /**
  69. * Make a form builder.
  70. *
  71. * @return Form
  72. */
  73. protected function form()
  74. {
  75. return Form::make(new BaseProduct(), function (Form $form) {
  76. $form->display('id');
  77. $form->text('title');
  78. $form->text('keywords');
  79. $form->text('description');
  80. $form->text('sku');
  81. $form->select('category_id', 'Category Name')
  82. ->options(BaseProductCategory::all()->pluck('name', 'id'))
  83. ->required();
  84. $form->text('publish_date');
  85. $form->text('order');
  86. $form->text('enabled');
  87. $form->text('content');
  88. $form->text('parameters');
  89. $form->display('created_at');
  90. $form->display('updated_at');
  91. });
  92. }
  93. }