12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- namespace App\Admin\Controllers;
- use App\Http\Controllers\Controller;
- use App\Model\Category;
- use Encore\Admin\Form;
- use Encore\Admin\Grid;
- use Encore\Admin\Facades\Admin;
- use Encore\Admin\Layout\Content;
- use Encore\Admin\Controllers\ModelForm;
- class CategoryController extends Controller
- {
- use ModelForm;
- public function index()
- {
- // return Admin::content(function (Content $content) {
- // $content->header('类目');
- // $content->description('列表');
- // $content->body($this->grid());
- // });
- return Admin::content(function (Content $content) {
- $content->header('脑图列表');
- $content->body(Category::tree(function ($tree) {
- $tree->branch(function ($branch) {
- return "{$branch['id']} - {$branch['category_name']}";
- });
- }));
- });
- }
- public function create()
- {
- return Admin::content(function (Content $content) {
- $content->header('脑图');
- $content->description('新增');
- $content->body($this->form());
- });
- }
- public function edit($id)
- {
- return Admin::content(function (Content $content) use ($id) {
- $content->header('脑图');
- $content->description();
- $content->body($this->form($id)->edit($id));
- });
- }
- protected function form($id = '')
- {
- return Admin::form(Category::class, function (Form $form) {
- $form->display('id' , '编号');
- $form->text('category_name' , '分类名称');
- $form->select('parent_id' , '选择分类')->options(Category::getCategory());
- $form->select('type' , '选择类型')->options([1 => '脑图中文' , 2 => '脑图英文']);
- $form->saving(function (Form $form) {
- if(is_null($form->parent_id)) {
- $form->parent_id = 0;
- }
- });
- });
- }
- // Grid
- protected function grid()
- {
- return Admin::grid(Category::class, function (Grid $grid) {
- $grid->id('编号')->sortable();
- //$grid->model()->orderBy('id','desc');
- $grid->category_name('类目名称');
- $grid->parent_id('父级名称')->display(function ($parent_id) {
- return $parent_id ? Category::getCategoryName($parent_id): '---';
- });
- $grid->paginate(20);
- // 禁用导出数据按钮
- $grid->actions(function ($actions) {
- $actions->disableView();
- //$actions->disableEdit();
- $actions->disableDelete();
- });
- //$grid->disableCreateButton();
- $grid->disableExport();
- $grid->filter(function ($filter) {
- $filter->disableIdFilter();
- });
- });
- }
- }
|