您现在的位置是:首页> 编程文章 个人博客模板
用 ORM 写无限极分类
无痕小Q个人博客
2020-04-12 02:04:12【
主页】
1360人已围观
简介实现无限极分类,运用场景为:树目录 / 部门分类 / 动态菜单等
直接上代码
模型

namespace App;
use Illuminate\Database\Eloquent\Model;
class AdminMenu extends Model
{
// 菜单表
protected $table = 'admin_menu';
protected $fillable = ['parent_id','order','title','icon','uri','permission'];
public function childCategory() {
return $this->hasMany('App\AdminMenu', 'parent_id', 'id')
->orderBy('order', 'asc');
}
public function all_list()
{
return $this->childCategory()->with('all_list');
}
}
protected $table = 'admin_menu';
protected $fillable = ['parent_id','order','title','icon','uri','permission'];
public function childCategory() {
return $this->hasMany('App\AdminMenu', 'parent_id', 'id')
->orderBy('order', 'asc');
}
public function all_list()
{
return $this->childCategory()->with('all_list');
}
}
protected $fillable = ['parent_id','order','title','icon','uri','permission'];
public function childCategory() {
return $this->hasMany('App\AdminMenu', 'parent_id', 'id')
->orderBy('order', 'asc');
}
public function all_list()
{
return $this->childCategory()->with('all_list');
}
}

public function list(){
$data = AdminMenu::with('all_list')
->where('parent_id',0)
->orderBy('order', 'asc')
->get();
return response()->success($data);
}
阅读量! (1360)
点击排行
要说酸甜苦辣都不足以形容人生的苦于乐,唯有一个熬字,各中滋味万千,身在其中的人最明白。
网站公告
- 欢迎来到我的博客
1:欢迎来到我的博客
2:博客免费api接口现已上线
3:博客会定期更新文章
4:欢迎大家来捧场
站点信息
相遇就是缘分,相处就是续缘,相知就是惜缘。爱的路上,没有早晚,也没有长短,只有是否珍惜。惊鸿一瞥的回眸,让心从此跟你走,无论朝朝暮暮,寒风酷暑;莞尔一笑的笑颜,让爱从此有了归属,无论人情冷暖,是风是雨
- 建站时间:2019-8-30
- 网站程序:php,laravel-swoole框架
- 今日流量:0(10分钟统计一次)
- 本月流量:0
- 浏览总量:396141
- 统计方式:中间件,redis消息队列,定时任务
申请链接友情链接
其一 天街小雨润如酥,草色遥看近却无。 最是一年春好处,绝胜烟柳满皇都。 其二 莫道官忙身老大,即无年少逐春心。 凭君先到江头看,柳色如今深未深。