PainterController.php 2.4 KB

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