filament model tree

在filament里实现laravel admin model tree,
filament无限分类管理。

《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
最佳答案

最近用 laravel-nestedset 实现过

  1. 安装 laravel-nestedset,添加数据库字段,设置模型;
  2. 资源列表页:关闭分页,这样会一次性显示所有的条目;
  3. 资源列表页:覆盖 getTableQuery 方法,parent::getTableQuery()->defaultOrder()->withDepth() 按顺序排列,方便渲染成树;
  4. 模型:增加 indentedName 属性,按照 depth 在开头添加空白字符
  // app/Models/Category.php
    protected function indentedName(): Attribute
    {
        return Attribute::make(
            get: fn($value, $attributes) => 
                Str::of("\u{00A0}")
                    ->repeat(6 * $attributes['depth'] ?? 0) . $attributes['name'],
        );
    }

file

2年前 评论
NewAim 2年前
讨论数量: 5

file

是树的

如果你需求是权限那样的树,参考dcat-admin 权限的源码。

没看 你说的是laravel-admin 那不知道

2年前 评论
ErzaQ (楼主) 2年前
lyxxxh (作者) 2年前

最近用 laravel-nestedset 实现过

  1. 安装 laravel-nestedset,添加数据库字段,设置模型;
  2. 资源列表页:关闭分页,这样会一次性显示所有的条目;
  3. 资源列表页:覆盖 getTableQuery 方法,parent::getTableQuery()->defaultOrder()->withDepth() 按顺序排列,方便渲染成树;
  4. 模型:增加 indentedName 属性,按照 depth 在开头添加空白字符
  // app/Models/Category.php
    protected function indentedName(): Attribute
    {
        return Attribute::make(
            get: fn($value, $attributes) => 
                Str::of("\u{00A0}")
                    ->repeat(6 * $attributes['depth'] ?? 0) . $attributes['name'],
        );
    }

file

2年前 评论
NewAim 2年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!