Home>Article>PHP Framework> Laravel admin implements classification tree/model tree

Laravel admin implements classification tree/model tree

Guanhui
Guanhui forward
2020-06-20 18:05:13 4706browse

Laravel admin implements classification tree/model tree

Modify model Category.php

setParentColumn('parent_id'); $this->setOrderColumn('sort'); $this->setTitleColumn('name'); } }

Modify control file CategoryController.php

header('商品分类管理'); $content->body(Category::tree(function ($tree) { $tree->branch(function ($branch) { $src = config('admin.upload.host') . '/' . $branch['image']; $logo = ""; return "{$branch['id']} - {$branch['name']} $logo"; }); })); }); } //下面是自己的代码 //....... }

Add routing app/Admin/routes.php

$router->resource('categories',CategoryController::class);

Using classification trees in select

$form->select('parent_id', __('Parent id'))->options(Category::selectOptions())->default(1);

Recommended tutorial: "Laravel Tutorial"

The above is the detailed content of Laravel admin implements classification tree/model tree. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:jb51.net. If there is any infringement, please contact admin@php.cn delete