海南旅游SAAS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.0 KiB

  1. <?php
  2. namespace App\AdminAgent\Controllers;
  3. use App\AdminAgent\Repositories\Slide;
  4. use Dcat\Admin\Admin;
  5. use Dcat\Admin\Form;
  6. use Dcat\Admin\Grid;
  7. use Dcat\Admin\Show;
  8. use Dcat\Admin\Http\Controllers\AdminController;
  9. class SlideController extends AdminController
  10. {
  11. /**
  12. * Make a grid builder.
  13. *
  14. * @return Grid
  15. */
  16. protected function grid()
  17. {
  18. return Grid::make(new Slide(), function (Grid $grid) {
  19. $grid->model()->where('agent_id', Admin::user()->id)->orderBy('sort');
  20. $grid->column('id')->sortable();
  21. $grid->column('title');
  22. $grid->column('url')->image('', 60, 60);
  23. $grid->column('status')->switch();
  24. $grid->column('sort')->editable()->sortable()->width(120);
  25. $grid->filter(function (Grid\Filter $filter) {
  26. $filter->equal('id');
  27. });
  28. });
  29. }
  30. /**
  31. * Make a show builder.
  32. *
  33. * @param mixed $id
  34. *
  35. * @return Show
  36. */
  37. protected function detail($id)
  38. {
  39. return Show::make($id, new Slide(), function (Show $show) {
  40. $show->field('id');
  41. $show->field('title');
  42. $show->field('url')->image('', 80, 80);
  43. $show->field('status')->using(['禁用', '启用']);
  44. $show->field('sort');
  45. $show->field('created_at');
  46. $show->field('updated_at');
  47. });
  48. }
  49. /**
  50. * Make a form builder.
  51. *
  52. * @return Form
  53. */
  54. protected function form()
  55. {
  56. return Form::make(new Slide(), function (Form $form) {
  57. $form->display('id');
  58. $form->text('title');
  59. $form->image('url')->required()->removable(false);
  60. $form->switch('status')->required();
  61. $form->text('sort')->required();
  62. })->saving(function (Form $form) {
  63. //处理特殊字段
  64. $form->hidden(['agent_id']);
  65. $form->agent_id = Admin::user()->id;
  66. $form->status = $form->status ? 1 : 0;
  67. });
  68. }
  69. }