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. * Make a grid builder.
  27. *
  28. * @return Grid
  29. */
  30. protected function grid()
  31. {
  32. return Admin::grid(YourModel::class, function (Grid $grid) {
  33. $grid->id('ID')->sortable();
  34. $grid->created_at();
  35. $grid->updated_at();
  36. });
  37. }
  38. /**
  39. * Edit interface.
  40. *
  41. * @param $id
  42. * @return Content
  43. */
  44. public function edit($id)
  45. {
  46. return Admin::content(function (Content $content) use ($id) {
  47. $content->header('header');
  48. $content->description('description');
  49. $content->body($this->form()->edit($id));
  50. });
  51. }
  52. /**
  53. * Make a form builder.
  54. *
  55. * @return Form
  56. */
  57. protected function form()
  58. {
  59. return Admin::form(YourModel::class, function (Form $form) {
  60. $form->display('id', 'ID');
  61. $form->display('created_at', 'Created At');
  62. $form->display('updated_at', 'Updated At');
  63. });
  64. }
  65. /**
  66. * Create interface.
  67. *
  68. * @return Content
  69. */
  70. public function create()
  71. {
  72. return Admin::content(function (Content $content) {
  73. $content->header('header');
  74. $content->description('description');
  75. $content->body($this->form());
  76. });
  77. }
  78. }