laravel-admin中tree树形列表数据怎么添加筛选条件显示数据代码

管理员 发布于 3年前   728

laravel-admin中tree树形列表数据怎么添加筛选条件显示数据代码呢?

我就直接贴代码:

tree型列表中直接添加where条件筛选

/**
* Index interface.
* @return Content
*/
public function index(Content $content)
{
   return $content
       ->header($this->title)
       ->description('列表')
       ->body($this->tree());
}

protected function tree()
{
   return CustomUrl::tree(function (Tree $tree) {
       //修改模型的查询
       $tree->query(function ($model) {
           return $model->where('id',2);
           //也可以用其他where参数 比如:$model->wherenotin('id',[1,2,3]
       });
       $tree->branch(function ($branch) {
           $branch['status']= $branch['status'] == 0 ? "启用" : "禁用";
           try{
               $branch['title'] = CustomUrl::find($branch['id'])->pageType->title;
               return "{$branch['id']} - {$branch['name']} - {$branch['title']} - {$branch['urlrule']} - {$branch['status']} ";
           }catch (\Exception $e){
               return "{$branch['id']} - 未定义 -  {$branch['urlrule']} - {$branch['status']}  ";
           }
       });
   });
}

效果:

image.png

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!

该博客于2020-12-7日,后端基于go语言的beego框架开发
前端页面使用Bootstrap可视化布局系统自动生成

是我仿的原来我的TP5框架写的博客,比较粗糙,底下是入口
侯体宗的博客

      订阅博客周刊

文章标签

友情链接

HouTiZong
侯体宗的博客
© 2020 zongscan.com
版权所有ICP证 : 粤ICP备20027696号
PHP交流群
侯体宗的博客