PainterController.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. * @return Show
  35. */
  36. protected function detail($id)
  37. {
  38. return Show::make($id, new Painter(), function (Show $show) {
  39. $show->id;
  40. $show->username;
  41. $show->bio;
  42. $show->created_at;
  43. $show->updated_at;
  44. $show->relation('paintings', function ($model) {
  45. return Grid::make(Painting::where('painter_id', $model->getKey()), function (Grid $grid) {
  46. $grid->column('id')->sortable();
  47. $grid->column('title');
  48. $grid->column('body');
  49. $grid->column('completed_at')->sortable();
  50. });
  51. });
  52. });
  53. }
  54. /**
  55. * Make a form builder.
  56. *
  57. * @return Form
  58. */
  59. protected function form()
  60. {
  61. return Form::make(Painter::with('paintings'), function (Form $form) {
  62. $form->block(6, function (Form\BlockForm $form) {
  63. $form->showFooter();
  64. $form->display('id', 'ID');
  65. $form->text('username')->rules('required');
  66. $form->textarea('bio')->rules('required');
  67. });
  68. $form->block(6, function (Form\BlockForm $form) {
  69. $form->hasMany('paintings', function (Form\NestedForm $form) {
  70. $form->text('title');
  71. $form->textarea('body');
  72. $form->datetime('completed_at');
  73. });
  74. $form->display('created_at', 'Created At');
  75. });
  76. });
  77. }
  78. }