ExampleController.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Http\Controllers\Controller;
  4. use Encore\Admin\Controllers\HasResourceActions;
  5. use Encore\Admin\Form;
  6. use Encore\Admin\Grid;
  7. use Encore\Admin\Layout\Content;
  8. use Encore\Admin\Show;
  9. class ExampleController extends Controller
  10. {
  11. use HasResourceActions;
  12. /**
  13. * Index interface.
  14. *
  15. * @param Content $content
  16. * @return Content
  17. */
  18. public function index(Content $content)
  19. {
  20. return $content
  21. ->header('Index')
  22. ->description('description')
  23. ->body($this->grid());
  24. }
  25. /**
  26. * Show interface.
  27. *
  28. * @param mixed $id
  29. * @param Content $content
  30. * @return Content
  31. */
  32. public function show($id, Content $content)
  33. {
  34. return $content
  35. ->header('Detail')
  36. ->description('description')
  37. ->body($this->detail($id));
  38. }
  39. /**
  40. * Edit interface.
  41. *
  42. * @param mixed $id
  43. * @param Content $content
  44. * @return Content
  45. */
  46. public function edit($id, Content $content)
  47. {
  48. return $content
  49. ->header('Edit')
  50. ->description('description')
  51. ->body($this->form()->edit($id));
  52. }
  53. /**
  54. * Create interface.
  55. *
  56. * @param Content $content
  57. * @return Content
  58. */
  59. public function create(Content $content)
  60. {
  61. return $content
  62. ->header('Create')
  63. ->description('description')
  64. ->body($this->form());
  65. }
  66. /**
  67. * Make a grid builder.
  68. *
  69. * @return Grid
  70. */
  71. protected function grid()
  72. {
  73. $grid = new Grid(new YourModel);
  74. $grid->id('ID')->sortable();
  75. $grid->created_at('Created at');
  76. $grid->updated_at('Updated at');
  77. return $grid;
  78. }
  79. /**
  80. * Make a show builder.
  81. *
  82. * @param mixed $id
  83. * @return Show
  84. */
  85. protected function detail($id)
  86. {
  87. $show = new Show(YourModel::findOrFail($id));
  88. $show->id('ID');
  89. $show->created_at('Created at');
  90. $show->updated_at('Updated at');
  91. return $show;
  92. }
  93. /**
  94. * Make a form builder.
  95. *
  96. * @return Form
  97. */
  98. protected function form()
  99. {
  100. $form = new Form(new YourModel);
  101. $form->display('id', 'ID');
  102. $form->display('created_at', 'Created At');
  103. $form->display('updated_at', 'Updated At');
  104. return $form;
  105. }
  106. }