DistProductController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. namespace App\Distributor\Controllers;
  3. use App\Distributor\Repositories\DistProduct;
  4. use Dcat\Admin\Form;
  5. use Dcat\Admin\Grid;
  6. use Dcat\Admin\Show;
  7. use Dcat\Admin\Http\Controllers\AdminController;
  8. use Dcat\Admin\Layout\Content;
  9. use Dcat\Admin\Admin;
  10. class DistProductController extends AdminController
  11. {
  12. /**
  13. * page index
  14. */
  15. public function index(Content $content)
  16. {
  17. return $content
  18. ->view('distributor.layouts.content')
  19. ->header(admin_trans( 'admin.products_list'))
  20. ->description(admin_trans('admin.all'))
  21. ->breadcrumb(['text'=>'list','url'=>''])
  22. ->body($this->grid());
  23. }
  24. /**
  25. * Edit interface.
  26. *
  27. * @param mixed $id
  28. * @param Content $content
  29. * @return Content
  30. */
  31. public function edit($id, Content $content)
  32. {
  33. return $content
  34. ->view('distributor.layouts.content')
  35. ->translation($this->translation())
  36. ->title($this->title())
  37. ->description($this->description()['edit'] ?? trans('admin.edit'))
  38. ->body($this->form()->edit($id));
  39. }
  40. /**
  41. * Create interface.
  42. *
  43. * @param Content $content
  44. * @return Content
  45. */
  46. public function create(Content $content)
  47. {
  48. return $content
  49. ->view('distributor.layouts.content')
  50. ->translation($this->translation())
  51. ->title($this->title())
  52. ->description($this->description()['create'] ?? trans('admin.create'))
  53. ->body($this->form());
  54. }
  55. /**
  56. * Make a grid builder.
  57. *
  58. * @return Grid
  59. */
  60. protected function grid()
  61. {
  62. return Grid::make(new DistProduct(), function (Grid $grid) {
  63. $grid->column('id')->sortable();
  64. $grid->column('title');
  65. $grid->column('keywords');
  66. $grid->column('description');
  67. $grid->column('sku');
  68. $grid->column('category_id');
  69. $grid->column('issuance_date');
  70. $grid->column('order');
  71. $grid->column('enabled');
  72. $grid->column('content');
  73. $grid->column('parameters');
  74. $grid->column('is_pinned');
  75. $grid->column('created_at');
  76. $grid->column('updated_at')->sortable();
  77. $grid->filter(function (Grid\Filter $filter) {
  78. $filter->equal('id');
  79. });
  80. });
  81. }
  82. /**
  83. * Make a show builder.
  84. *
  85. * @param mixed $id
  86. *
  87. * @return Show
  88. */
  89. protected function detail($id)
  90. {
  91. return Show::make($id, new DistProduct(), function (Show $show) {
  92. $show->field('id');
  93. $show->field('title');
  94. $show->field('keywords');
  95. $show->field('description');
  96. $show->field('sku');
  97. $show->field('category_id');
  98. $show->field('issuance_date');
  99. $show->field('order');
  100. $show->field('enabled');
  101. $show->field('content');
  102. $show->field('parameters');
  103. $show->field('is_pinned');
  104. $show->field('created_at');
  105. $show->field('updated_at');
  106. });
  107. }
  108. /**
  109. * Make a form builder.
  110. *
  111. * @return Form
  112. */
  113. protected function form()
  114. {
  115. return Form::make(new DistProduct(), function (Form $form) {
  116. $form->display('id');
  117. $form->text('title');
  118. $form->text('keywords');
  119. $form->text('description');
  120. $form->text('sku');
  121. $form->text('category_id');
  122. $form->text('issuance_date');
  123. $form->text('order');
  124. $form->text('enabled');
  125. $form->text('content');
  126. $form->text('parameters');
  127. $form->text('is_pinned');
  128. $form->display('created_at');
  129. $form->display('updated_at');
  130. });
  131. }
  132. }