ExampleController.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use Encore\Admin\Form;
  4. use Encore\Admin\Grid;
  5. use Encore\Admin\Facades\Admin;
  6. use Encore\Admin\Layout\Content;
  7. use App\Http\Controllers\Controller;
  8. use Encore\Admin\Controllers\ModelForm;
  9. class ExampleController extends Controller
  10. {
  11. use ModelForm;
  12. /**
  13. * Index interface.
  14. *
  15. * @return Content
  16. */
  17. public function index()
  18. {
  19. return Admin::content(function (Content $content) {
  20. $content->header('header');
  21. $content->description('description');
  22. $content->body($this->grid());
  23. });
  24. }
  25. /**
  26. * Edit interface.
  27. *
  28. * @param $id
  29. * @return Content
  30. */
  31. public function edit($id)
  32. {
  33. return Admin::content(function (Content $content) use ($id) {
  34. $content->header('header');
  35. $content->description('description');
  36. $content->body($this->form()->edit($id));
  37. });
  38. }
  39. /**
  40. * Create interface.
  41. *
  42. * @return Content
  43. */
  44. public function create()
  45. {
  46. return Admin::content(function (Content $content) {
  47. $content->header('header');
  48. $content->description('description');
  49. $content->body($this->form());
  50. });
  51. }
  52. /**
  53. * Make a grid builder.
  54. *
  55. * @return Grid
  56. */
  57. protected function grid()
  58. {
  59. return Admin::grid(YourModel::class, function (Grid $grid) {
  60. $grid->id('序号')->sortable();
  61. $grid->created_at();
  62. $grid->updated_at();
  63. });
  64. }
  65. /**
  66. * Make a form builder.
  67. *
  68. * @return Form
  69. */
  70. protected function form()
  71. {
  72. return Admin::form(YourModel::class, function (Form $form) {
  73. $form->display('id', '序号');
  74. $form->display('created_at', 'Created At');
  75. $form->display('updated_at', 'Updated At');
  76. });
  77. }
  78. }