PainterController.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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->equal('id');
  26. });
  27. });
  28. }
  29. /**
  30. * Make a show builder.
  31. *
  32. * @param mixed $id
  33. *
  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->display('id', 'ID');
  63. $form->text('username')->rules('required');
  64. $form->textarea('bio')->rules('required');
  65. $form->hasMany('paintings', function (Form\NestedForm $form) {
  66. $form->text('title');
  67. $form->textarea('body');
  68. $form->datetime('completed_at');
  69. });
  70. $form->display('created_at', 'Created At');
  71. });
  72. }
  73. }