修改模型Category.php
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
<?php
namespace App\\Admin\\Models;
use Encore\\Admin\\Traits\\AdminBuilder;
use Encore\\Admin\\Traits\\ModelTree;
use Illuminate\\Database\\Eloquent\\Model;
class Category extends Model
{
use ModelTree, AdminBuilder;
protected $table = 'category';
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
//这里根据自己的字段修改
$this->setParentColumn('parent_id');
$this->setOrderColumn('sort');
$this->setTitleColumn('name');
}
}
|
修改控制文件CategoryController.php
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
<?php
namespace App\\Admin\\Controllers;
use App\\Admin\\Models\\Category;
use Encore\\Admin\\Controllers\\AdminController;
use Encore\\Admin\\Facades\\Admin;
use Encore\\Admin\\Layout\\Content;
use Encore\\Admin\\Show;
class CategoryController extends AdminController
{
/**
* Title for current resource.
*
* @var string
*/
protected $title = '商品分类管理';
public function index(Content $content)
{
return Admin::content(function ($content) {
$content->header('商品分类管理');
$content->body(Category::tree(function ($tree) {
$tree->branch(function ($branch) {
$src = config('admin.upload.host') . '/' . $branch['image'];
$logo = "<img src='$src' style='max-width:30px;max-height:30px' class='img'/>";
return "{$branch['id']} - {$branch['name']} $logo";
});
}));
});
}
//下面是自己的代码
//.......
}
|
添加路由app/Admin/routes.php
?
|
1
|
$router->resource('categories',CategoryController::class);
|
select中使用分类树
?
|
1
|
$form->select('parent_id', __('Parent id'))->options(Category::selectOptions())->default(1);
|
总结
到此这篇关于laravel admin实现分类树/模型树的示例代码的文章就介绍到这了,更多相关laravel admin 分类树 模型树内容请搜索快网idc以前的文章或继续浏览下面的相关文章希望大家以后多多支持快网idc!
原文链接:https://blog.csdn.net/xiayu204575/article/details/106611545
相关文章
猜你喜欢
- 个人服务器网站搭建:如何选择适合自己的建站程序或框架? 2025-06-10
- 64M VPS建站:能否支持高流量网站运行? 2025-06-10
- 64M VPS建站:怎样选择合适的域名和SSL证书? 2025-06-10
- 64M VPS建站:怎样优化以提高网站加载速度? 2025-06-10
- 64M VPS建站:是否适合初学者操作和管理? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-05-27 39
-
2025-05-25 78
-
Dotnet Core 技术之Dotnet 6.0 深度探索
2025-05-29 79 -
2025-05-25 86
-
2025-05-27 74
热门评论

