TestController.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Repositories\Test;
  4. use Dcat\Admin\Form;
  5. use Dcat\Admin\Grid;
  6. use Dcat\Admin\Show;
  7. use Dcat\Admin\Http\Controllers\AdminController;
  8. use Carbon\Carbon;
  9. class TestController extends AdminController
  10. {
  11. /**
  12. * Make a grid builder.
  13. *
  14. * @return Grid
  15. */
  16. protected function grid()
  17. {
  18. return Grid::make(new Test(), function (Grid $grid) {
  19. $grid->column('id')->sortable();
  20. $grid->column('name');
  21. $grid->column('created_at');
  22. $grid->column('updated_at')->sortable();
  23. $grid->filter(function (Grid\Filter $filter) {
  24. $filter->equal('id');
  25. });
  26. });
  27. }
  28. /**
  29. * Make a show builder.
  30. *
  31. * @param mixed $id
  32. *
  33. * @return Show
  34. */
  35. protected function detail($id)
  36. {
  37. return Show::make($id, new Test(), function (Show $show) {
  38. $show->field('id');
  39. $show->field('name');
  40. $show->field('created_at');
  41. $show->field('updated_at');
  42. });
  43. }
  44. /**
  45. * Make a form builder.
  46. *
  47. * @return Form
  48. */
  49. protected function form()
  50. {
  51. return Form::make(new Test(), function (Form $form) {
  52. $form->display('id');
  53. $form->multipleImage('name')->saving(function ($paths) {
  54. return json_encode($paths);
  55. })->move('images/product/'.date("Ymd").'/')
  56. ->uniqueName()
  57. ->autoUpload()
  58. ->accept('jpg,png,gif,jpeg,webp');
  59. $form->display('created_at');
  60. $form->display('updated_at');
  61. });
  62. }
  63. }