Home > PHP Framework > Laravel > body text

Laravel admin implements classification tree/model tree

Guanhui
Release: 2020-06-22 14:27:18
forward
4616 people have browsed it

Laravel admin implements classification tree/model tree

Modify model Category.php

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

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";
    });
   }));
  });
 }
	//下面是自己的代码
	//.......
 }
Copy after login

Add routing app/Admin/routes.php

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

Using classification trees in select

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

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!

Related labels:
source:jb51.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!