RecommendationsController.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Models\Config;
  4. use Dcat\Admin\Form;
  5. use Dcat\Admin\Grid;
  6. use Dcat\Admin\Show;
  7. use Dcat\Admin\Http\Controllers\AdminController;
  8. class RecommendationsController extends AdminController
  9. {
  10. /**
  11. * Make a grid builder.
  12. *
  13. * @return Grid
  14. */
  15. protected function grid()
  16. {
  17. return Grid::make(new Config(), function (Grid $grid) {
  18. $grid->model()->whereIn('id', [3, 13, 4]);
  19. $grid->column('id')->sortable();
  20. $grid->column('desc', '标题');
  21. $grid->column('value', '值')->display(function ($item) {
  22. if (3 == $this->id) {
  23. return $item . '%';
  24. }
  25. if (4 == $this->id) {
  26. return $item . '元';
  27. }
  28. return $item;
  29. });
  30. $grid->column('created_at');
  31. $grid->column('updated_at')->sortable();
  32. $grid->disableDeleteButton();
  33. $grid->disableCreateButton();
  34. $grid->disableViewButton();
  35. });
  36. }
  37. /**
  38. * Make a show builder.
  39. *
  40. * @return Show
  41. */
  42. protected function detail($id)
  43. {
  44. return Show::make($id, new Config(), function (Show $show) {
  45. $show->field('id');
  46. $show->field('key');
  47. $show->field('value');
  48. $show->field('desc');
  49. $show->field('created_at');
  50. $show->field('updated_at');
  51. });
  52. }
  53. /**
  54. * Make a form builder.
  55. *
  56. * @return Form
  57. */
  58. protected function form()
  59. {
  60. return Form::make(new Config(), function (Form $form) {
  61. $form->display('id');
  62. $form->text('value', '值')->required();
  63. $form->display('desc', '标题');
  64. $form->disableViewButton();
  65. $form->disableDeleteButton();
  66. });
  67. }
  68. }