EpisodesCategoryController.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace App\Admin\Controllers\Episode;
  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. use Dingo\Api\Http\Request;
  9. class EpisodesCategoryController extends AdminController
  10. {
  11. /**
  12. * Make a grid builder.
  13. *
  14. * @return Grid
  15. */
  16. protected function grid()
  17. {
  18. return Grid::make(new EpisodesCategory(), function (Grid $grid) {
  19. $grid->column('id')->sortable();
  20. $grid->column('name');
  21. $grid->column('pid','父分类')->display(function () {
  22. /* @var EpisodesCategory $this*/
  23. return $this->parent ?$this->parent->name : '';
  24. });
  25. $grid->column('created_at');
  26. $grid->disableRowSelector();
  27. $grid->disableViewButton();
  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 EpisodesCategory(), function (Show $show) {
  40. $show->field('id');
  41. $show->field('name');
  42. $show->field('pid');
  43. $show->field('path');
  44. $show->field('sort');
  45. $show->field('created_at');
  46. $show->field('updated_at');
  47. });
  48. }
  49. /**
  50. * Make a form builder.
  51. *
  52. * @return Form
  53. */
  54. protected function form()
  55. {
  56. return Form::make(new EpisodesCategory(), function (Form $form) {
  57. $categoryModel = app(\App\Models\EpisodesCategory::class);
  58. $options = $categoryModel::select(['id','name'])->where('pid',0)->get()->toArray();
  59. array_unshift($options,['id' => 0, 'name' => '一级分类']);
  60. $options = array_column($options,'name','id');
  61. $form->display('id');
  62. $form->select('pid')->options($options);
  63. $form->text('name');
  64. $form->disableViewButton();
  65. $form->disableDeleteButton();
  66. $form->disableListButton();
  67. $form->disableEditingCheck();
  68. $form->disableViewCheck();
  69. $form->disableCreatingCheck();
  70. });
  71. }
  72. public function options(Request $request)
  73. {
  74. $q = $request->get('q');
  75. $categoryModel = app(\App\Models\EpisodesCategory::class);
  76. return $categoryModel->where('name', 'like', "%$q%")->paginate(null, ['id', 'name as text']);
  77. }
  78. }