SpecialistColumnController.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use Encore\Admin\Controllers\AdminController;
  4. use Encore\Admin\Form;
  5. use Encore\Admin\Grid;
  6. use Encore\Admin\Show;
  7. use App\Models\SpecialistCloumn;
  8. class SpecialistColumnController extends AdminController
  9. {
  10. /**
  11. * Title for current resource.
  12. *
  13. * @var string
  14. */
  15. protected $title = '健康课堂-一级栏目管理';
  16. /**
  17. * Make a grid builder.
  18. *
  19. * @return Grid
  20. */
  21. protected function grid()
  22. {
  23. $grid = new Grid(new SpecialistCloumn);
  24. // 禁用创建按钮
  25. // $grid->disableCreateButton();
  26. // 禁用编辑功能
  27. // $grid->disableActions();
  28. $grid->column('id', __('ID'))->sortable();
  29. $grid->column('name', __('名称'));
  30. $grid->column('is_show', __('是否显示'));
  31. // ->display(function ($isShow) {
  32. // return SpecialistCloumn::$isShowMap[$isShow];
  33. // });
  34. $grid->column('rank', __('排序(越大越靠前)'))->sortable();
  35. $grid->column('created_at', __('创建时间'));
  36. $grid->column('updated_at', __('更新时间'));
  37. $grid->model()->where('pid', SpecialistCloumn::PID_0);
  38. // 新增过滤
  39. $grid->filter(function ($filter) {
  40. $filter->like('name', '名称');
  41. $filter->equal('is_show', '是否显示')->radio(SpecialistCloumn::$isShowMap);
  42. });
  43. return $grid;
  44. }
  45. /**
  46. * Make a show builder.
  47. *
  48. * @param mixed $id
  49. * @return Show
  50. */
  51. protected function detail($id)
  52. {
  53. $show = new Show(SpecialistCloumn::findOrFail($id));
  54. $show->field('id', __('ID'));
  55. $show->field('created_at', __('Created at'));
  56. $show->field('updated_at', __('Updated at'));
  57. return $show;
  58. }
  59. /**
  60. * Make a form builder.
  61. *
  62. * @return Form
  63. */
  64. protected function form()
  65. {
  66. $form = new Form(new SpecialistCloumn);
  67. $form->display('id', __('ID'))->rules('required');
  68. $form->text('name', __('名称'))->rules('required');
  69. $form->image('pic', __('图片'))->uniqueName()->move('pics/'.date('Y').'/'.date('m'))->rules('required');
  70. $form->text('url', __('链接地址'))->rules('required');
  71. $form->table('banner', function ($table) {
  72. $table->image('src', '广告图')->uniqueName()->move('pics/'.date('Y').'/'.date('m'))->rules('required');
  73. $table->text('url', '链接地址')->rules('required');
  74. });
  75. $states = [
  76. 'on' => ['value' => 1, 'text' => '显示', 'color' => 'success'],
  77. 'off' => ['value' => 0, 'text' => '不显示', 'color' => 'danger'],
  78. ];
  79. $form->switch('is_show', __('是否显示'))->states($states);
  80. $form->number('rank', __('排序(越大越靠前)'))->default(0);
  81. return $form;
  82. }
  83. }