RecommendationsController.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 ($this->id == 3){
  23. return $item.'%';
  24. }
  25. if ($this->id == 4){
  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. * @param mixed $id
  41. *
  42. * @return Show
  43. */
  44. protected function detail($id)
  45. {
  46. return Show::make($id, new Config(), function (Show $show) {
  47. $show->field('id');
  48. $show->field('key');
  49. $show->field('value');
  50. $show->field('desc');
  51. $show->field('created_at');
  52. $show->field('updated_at');
  53. });
  54. }
  55. /**
  56. * Make a form builder.
  57. *
  58. * @return Form
  59. */
  60. protected function form()
  61. {
  62. return Form::make(new Config(), function (Form $form) {
  63. $form->display('id');
  64. $form->text('value','值')->required();
  65. $form->display('desc','标题');
  66. $form->disableViewButton();
  67. $form->disableDeleteButton();
  68. });
  69. }
  70. }