PainterController.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace Tests\Controllers;
  3. use Dcat\Admin\Form;
  4. use Dcat\Admin\Grid;
  5. use Dcat\Admin\Http\Controllers\AdminController;
  6. use Dcat\Admin\Show;
  7. use Faker\Factory;
  8. use Tests\Models\Painter;
  9. use Tests\Models\Painting;
  10. class PainterController extends AdminController
  11. {
  12. /**
  13. * Make a grid builder.
  14. *
  15. * @return Grid
  16. */
  17. protected function grid()
  18. {
  19. return Grid::make(new Painter(), function (Grid $grid) {
  20. $grid->id->sortable();
  21. $grid->username;
  22. $grid->bio;
  23. $grid->created_at;
  24. $grid->updated_at->sortable();
  25. $grid->filter(function (Grid\Filter $filter) {
  26. $filter->between('created_at')->datetime();
  27. $filter->equal('id');
  28. });
  29. });
  30. }
  31. /**
  32. * Make a show builder.
  33. *
  34. * @param mixed $id
  35. *
  36. * @return Show
  37. */
  38. protected function detail($id)
  39. {
  40. return Show::make($id, new Painter(), function (Show $show) {
  41. $show->id;
  42. $show->username;
  43. $show->bio;
  44. $show->created_at;
  45. $show->updated_at;
  46. $show->relation('paintings', function ($model) {
  47. return Grid::make(Painting::where('painter_id', $model->getKey()), function (Grid $grid) {
  48. $grid->column('id')->sortable();
  49. $grid->column('title');
  50. $grid->column('body');
  51. $grid->column('completed_at')->sortable();
  52. });
  53. });
  54. });
  55. }
  56. /**
  57. * Make a form builder.
  58. *
  59. * @return Form
  60. */
  61. protected function form()
  62. {
  63. return Form::make(Painter::with('paintings'), function (Form $form) {
  64. $form->display('id', 'ID');
  65. $form->text('username')->rules('required');
  66. $form->textarea('bio')->rules('required');
  67. $form->hasMany('paintings', function (Form\NestedForm $form) {
  68. $form->text('title');
  69. $form->textarea('body');
  70. $form->datetime('completed_at');
  71. });
  72. $form->display('created_at', 'Created At');
  73. });
  74. }
  75. }