FileController.php 2.1 KB

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