EpisodesCategoryController.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Models\EpisodesCategory;
  4. use Dcat\Admin\Form;
  5. use Dcat\Admin\Grid;
  6. use Dcat\Admin\Show;
  7. use Dcat\Admin\Http\Controllers\AdminController;
  8. class EpisodesCategoryController extends AdminController
  9. {
  10. /**
  11. * Make a grid builder.
  12. *
  13. * @return Grid
  14. */
  15. protected function grid()
  16. {
  17. return Grid::make(new EpisodesCategory(), function (Grid $grid) {
  18. $grid->column('id')->sortable();
  19. $grid->column('name');
  20. $grid->column('pid','父分类')->display(function () {
  21. /* @var EpisodesCategory $this*/
  22. return $this->parent ?$this->parent->name : '';
  23. });;
  24. $grid->column('created_at');
  25. });
  26. }
  27. /**
  28. * Make a show builder.
  29. *
  30. * @param mixed $id
  31. *
  32. * @return Show
  33. */
  34. protected function detail($id)
  35. {
  36. return Show::make($id, new EpisodesCategory(), function (Show $show) {
  37. $show->field('id');
  38. $show->field('name');
  39. $show->field('pid');
  40. $show->field('path');
  41. $show->field('sort');
  42. $show->field('created_at');
  43. $show->field('updated_at');
  44. });
  45. }
  46. /**
  47. * Make a form builder.
  48. *
  49. * @return Form
  50. */
  51. protected function form()
  52. {
  53. return Form::make(new EpisodesCategory(), function (Form $form) {
  54. $categoryModel = app(\App\Models\EpisodesCategory::class);
  55. $options = $categoryModel::select(['id','name'])->where('pid',0)->get()->toArray();
  56. array_unshift($options,['id' => 0, 'name' => '顶级分类']);
  57. $options = array_column($options,'name','id');
  58. $form->display('id');
  59. $form->select('pid')->options($options);
  60. $form->text('name');
  61. });
  62. }
  63. }