InsuranceAgreementController.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace App\Admin\Controllers\ServicePacksManagment;
  3. use App\Models\InsuranceAgreement;
  4. use Encore\Admin\Controllers\AdminController;
  5. use Encore\Admin\Form;
  6. use Encore\Admin\Grid;
  7. use Encore\Admin\Show;
  8. class InsuranceAgreementController 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 InsuranceAgreement());
  24. $grid->disableBatchActions();
  25. $grid->filter(function ($filter){
  26. $filter->disableIdFilter();
  27. $filter->like('name','协议名称');
  28. });
  29. $grid->column('id', __('Id'));
  30. $grid->column('name', __('协议名称'));
  31. // $grid->column('content', __('协议内容'))->limit('300','...');
  32. $status = [
  33. 'off' => ['value' => 0, 'text' => '禁用', 'color' => 'danger'],
  34. 'on' => ['value' => 1, 'text' => '启用', 'color' => 'success'],
  35. ];
  36. $grid->column('status', __('状态'))->switch($status);
  37. $grid->column('created_at', __('创建时间'));
  38. $grid->column('updated_at', __('更新时间'));
  39. return $grid;
  40. }
  41. /**
  42. * Make a show builder.
  43. *
  44. * @param mixed $id
  45. * @return Show
  46. */
  47. protected function detail($id)
  48. {
  49. $show = new Show(InsuranceAgreement::findOrFail($id));
  50. $show->field('id', 'ID');
  51. $show->field('name', '协议名称');
  52. $show->field('content', '协议内容')->unescape();
  53. $show->field('status', '状态')->using([0=>'禁用',1=>'启用'])->label('info');
  54. $show->field('created_at', '创建时间');
  55. $show->field('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 InsuranceAgreement());
  66. $form->text('name', __('协议名称'));
  67. $form->editor('content', __('协议内容'));
  68. $status = [
  69. 'off' => ['value' => 0, 'text' => '禁用', 'color' => 'danger'],
  70. 'on' => ['value' => 1, 'text' => '启用', 'color' => 'success'],
  71. ];
  72. $form->switch('status', __('状态'))->states($status)->default(1);
  73. return $form;
  74. }
  75. }