InvoiceCategoryController.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. namespace App\Admin\Controllers\Company;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\InvoiceCategory;
  5. use Encore\Admin\Auth\Permission;
  6. use Encore\Admin\Controllers\HasResourceActions;
  7. use Encore\Admin\Facades\Admin;
  8. use Encore\Admin\Form;
  9. use Encore\Admin\Grid;
  10. use Encore\Admin\Layout\Content;
  11. use Encore\Admin\Show;
  12. class InvoiceCategoryController extends Controller
  13. {
  14. use HasResourceActions;
  15. /**
  16. * Index interface.
  17. *
  18. * @param Content $content
  19. * @return Content
  20. */
  21. public function index(Content $content)
  22. {
  23. Permission::check('invoice_manager_category');
  24. return $content
  25. ->header('发票分类')
  26. ->description('列表')
  27. ->body($this->grid());
  28. }
  29. /**
  30. * Show interface.
  31. *
  32. * @param mixed $id
  33. * @param Content $content
  34. * @return Content
  35. */
  36. public function show($id, Content $content)
  37. {
  38. return $content
  39. ->header('Detail')
  40. ->description('description')
  41. ->body($this->detail($id));
  42. }
  43. /**
  44. * Edit interface.
  45. *
  46. * @param mixed $id
  47. * @param Content $content
  48. * @return Content
  49. */
  50. public function edit($id, Content $content)
  51. {
  52. return $content
  53. ->header('发票分类')
  54. ->description('编辑')
  55. ->body($this->form()->edit($id));
  56. }
  57. /**
  58. * Create interface.
  59. *
  60. * @param Content $content
  61. * @return Content
  62. */
  63. public function create(Content $content)
  64. {
  65. return $content
  66. ->header('发票分类')
  67. ->description('新增')
  68. ->body($this->form());
  69. }
  70. /**
  71. * Make a grid builder.
  72. *
  73. * @return Grid
  74. */
  75. protected function grid()
  76. {
  77. Permission::check('invoice_manager_category');
  78. $grid = new Grid(new InvoiceCategory);
  79. $grid->model()->orderby('id', 'asc');
  80. $grid->categoryname('分类名称')->editable();
  81. $grid->admin_set('类型')->display(function ($admin_set) {
  82. if ($admin_set == 1) {
  83. return '系统设置';
  84. }
  85. });
  86. $grid->category_order('分类排序')->editable();
  87. $grid->created_at('添加时间');
  88. $grid->disableFilter();
  89. if (Admin::user()->can('invoice_manager_category_add')) {
  90. $grid->disableCreateButton(false);
  91. }
  92. $grid->actions(function ($actions) {
  93. if (Admin::user()->can('invoice_manager_category_delete')) {
  94. $actions->disableDelete(false);
  95. }
  96. });
  97. return $grid;
  98. }
  99. /**
  100. * Make a show builder.
  101. *
  102. * @param mixed $id
  103. * @return Show
  104. */
  105. protected function detail($id)
  106. {
  107. $show = new Show(InvoiceCategory::findOrFail($id));
  108. $show->admin_set('类型')->as(function ($admin_set) {
  109. if ($admin_set == 1) {
  110. return '系统设置';
  111. }
  112. });
  113. $show->category_order('分类排序')->editable();
  114. $show->created_at('添加时间');
  115. return $show;
  116. }
  117. /**
  118. * Make a form builder.
  119. *
  120. * @return Form
  121. */
  122. protected function form()
  123. {
  124. $form = new Form(new InvoiceCategory);
  125. $form->text('categoryname', '分类名称');
  126. $form->text('category_order', '分类排序');
  127. return $form;
  128. }
  129. }