123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- <?php
- namespace App\Admin\Controllers\Company;
- use App\Http\Controllers\Controller;
- use App\Models\InvoiceCategory;
- use Encore\Admin\Auth\Permission;
- use Encore\Admin\Controllers\HasResourceActions;
- use Encore\Admin\Facades\Admin;
- use Encore\Admin\Form;
- use Encore\Admin\Grid;
- use Encore\Admin\Layout\Content;
- use Encore\Admin\Show;
- class InvoiceCategoryController extends Controller
- {
- use HasResourceActions;
- /**
- * Index interface.
- *
- * @param Content $content
- * @return Content
- */
- public function index(Content $content)
- {
- Permission::check('invoice_manager_category');
- return $content
- ->header('发票分类')
- ->description('列表')
- ->body($this->grid());
- }
- /**
- * Show interface.
- *
- * @param mixed $id
- * @param Content $content
- * @return Content
- */
- public function show($id, Content $content)
- {
- return $content
- ->header('Detail')
- ->description('description')
- ->body($this->detail($id));
- }
- /**
- * Edit interface.
- *
- * @param mixed $id
- * @param Content $content
- * @return Content
- */
- public function edit($id, Content $content)
- {
- return $content
- ->header('发票分类')
- ->description('编辑')
- ->body($this->form()->edit($id));
- }
- /**
- * Create interface.
- *
- * @param Content $content
- * @return Content
- */
- public function create(Content $content)
- {
- return $content
- ->header('发票分类')
- ->description('新增')
- ->body($this->form());
- }
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- Permission::check('invoice_manager_category');
- $grid = new Grid(new InvoiceCategory);
- $grid->model()->orderby('id', 'asc');
- $grid->categoryname('分类名称')->editable();
- $grid->admin_set('类型')->display(function ($admin_set) {
- if ($admin_set == 1) {
- return '系统设置';
- }
- });
- $grid->category_order('分类排序')->editable();
- $grid->created_at('添加时间');
- $grid->disableFilter();
- if (Admin::user()->can('invoice_manager_category_add')) {
- $grid->disableCreateButton(false);
- }
- $grid->actions(function ($actions) {
- if (Admin::user()->can('invoice_manager_category_delete')) {
- $actions->disableDelete(false);
- }
- });
- return $grid;
- }
- /**
- * Make a show builder.
- *
- * @param mixed $id
- * @return Show
- */
- protected function detail($id)
- {
- $show = new Show(InvoiceCategory::findOrFail($id));
- $show->admin_set('类型')->as(function ($admin_set) {
- if ($admin_set == 1) {
- return '系统设置';
- }
- });
- $show->category_order('分类排序')->editable();
- $show->created_at('添加时间');
- return $show;
- }
- /**
- * Make a form builder.
- *
- * @return Form
- */
- protected function form()
- {
- $form = new Form(new InvoiceCategory);
- $form->text('categoryname', '分类名称');
- $form->text('category_order', '分类排序');
- return $form;
- }
- }
|