SpecialistColumnController.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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', __('是否显示'))->display(function ($isShow) {
  31. return SpecialistCloumn::$isShowMap[$isShow];
  32. });;
  33. $grid->column('rank', __('排序(越大越靠前)'))->sortable();
  34. $grid->column('created_at', __('创建时间'));
  35. $grid->column('updated_at', __('更新时间'));
  36. $grid->model()->where('pid', SpecialistCloumn::PID_0);
  37. // 新增过滤
  38. $grid->filter(function ($filter) {
  39. $filter->like('name', '名称');
  40. $filter->equal('is_show', '是否显示')->radio(SpecialistCloumn::$isShowMap);
  41. });
  42. return $grid;
  43. }
  44. /**
  45. * Make a show builder.
  46. *
  47. * @param mixed $id
  48. * @return Show
  49. */
  50. protected function detail($id)
  51. {
  52. $show = new Show(SpecialistCloumn::findOrFail($id));
  53. $show->field('id', __('ID'));
  54. $show->field('created_at', __('Created at'));
  55. $show->field('updated_at', __('Updated at'));
  56. return $show;
  57. }
  58. /**
  59. * Make a form builder.
  60. *
  61. * @return Form
  62. */
  63. protected function form()
  64. {
  65. $form = new Form(new SpecialistCloumn);
  66. $form->display('id', __('ID'))->rules('required');
  67. $form->text('name', __('名称'))->rules('required');
  68. $form->image('pic', __('图片'))->uniqueName()->move('pics/'.date('Y').'/'.date('m'))->rules('required');
  69. $form->text('url', __('链接地址'))->rules('required');
  70. $form->table('banner', function ($table) {
  71. $table->image('src', '广告图')->uniqueName()->move('pics/'.date('Y').'/'.date('m'))->rules('required');
  72. $table->text('url', '链接地址')->rules('required');
  73. });
  74. $states = [
  75. 'on' => ['value' => 1, 'text' => '显示', 'color' => 'success'],
  76. 'off' => ['value' => 0, 'text' => '不显示', 'color' => 'danger'],
  77. ];
  78. $form->switch('is_show', __('是否显示'))->states($states);
  79. $form->number('rank', __('排序(越大越靠前)'))->default(0);
  80. return $form;
  81. }
  82. }