MentalityDrillExtendController.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Models\MentalityDrillCategory;
  4. use App\Models\MentalityDrillExtend;
  5. use Encore\Admin\Controllers\AdminController;
  6. use Encore\Admin\Form;
  7. use Encore\Admin\Grid;
  8. use Encore\Admin\Show;
  9. use App\Models\MentalityDrill;
  10. class MentalityDrillExtendController extends AdminController
  11. {
  12. /**
  13. * Title for current resource.
  14. *
  15. * @var string
  16. */
  17. protected $title = '音视频';
  18. /**
  19. * Make a grid builder.
  20. *
  21. * @return Grid
  22. */
  23. protected function grid()
  24. {
  25. $grid = new Grid(new MentalityDrillExtend());
  26. $grid->filter(function(\Encore\Admin\Grid\Filter $filter){
  27. // 在这里添加字段过滤器
  28. $filter->like('name', '名称');
  29. $filter->expand();
  30. });
  31. $grid->column('id', __('Id'));
  32. $grid->column('drill_id', __('训练'))->display(function ($id) {
  33. if ($id > 0){
  34. $mentalityDrillData = MentalityDrill::find($id);
  35. if ($mentalityDrillData){
  36. return $mentalityDrillData->title;
  37. }
  38. }
  39. return '';
  40. });
  41. $grid->column('name', __('名称'));
  42. $grid->column('time', __('时长'));
  43. $grid->column('type', __('类别'))->display(function ($type) {
  44. return MentalityDrillExtend::$typeMap[$type];
  45. });
  46. $grid->column('created_at', __('创建时间'));
  47. $grid->column('updated_at', __('更新时间'));
  48. return $grid;
  49. }
  50. /**
  51. * Make a show builder.
  52. *
  53. * @param mixed $id
  54. * @return Show
  55. */
  56. protected function detail($id)
  57. {
  58. $show = new Show(MentalityDrillExtend::findOrFail($id));
  59. $show->field('id', __('Id'));
  60. $show->field('drill_id', __('Drill id'));
  61. $show->field('name', __('Name'));
  62. $show->field('time', __('Time'));
  63. $show->field('src', __('Src'));
  64. $show->field('created_at', __('Created at'));
  65. $show->field('updated_at', __('Updated at'));
  66. $show->field('deleted_at', __('Deleted at'));
  67. return $show;
  68. }
  69. /**
  70. * Make a form builder.
  71. *
  72. * @return Form
  73. */
  74. protected function form()
  75. {
  76. $form = new Form(new MentalityDrillExtend());
  77. $select = MentalityDrill::get(['id','title as name'])->pluck('name','id');
  78. $form->select('drill_id', __('训练'))->options($select)->required();
  79. $form->select('type', __('类别'))->options(MentalityDrillExtend::$typeMap)->required();
  80. $form->text('name', __('名称'))->required();
  81. $form->text('time', __('时长'))->required();
  82. $form->file('src', __('音视频'))->removable()->uniqueName()->move('videos/'.date('Y').'/'.date('m'));
  83. $form->image('pic', __('背景图片'));
  84. return $form;
  85. }
  86. }