【发布时间】:2019-01-17 16:59:06
【问题描述】:
我有 1 个类别和子类别表 table name: categories
另一个表是帖子posts table
当点击谷歌应用脚本时,所有关于谷歌应用脚本类别和子类别的帖子都会显示enter image description here
我的控制器代码是,控制器名称是 bloglistController
$posts = post::where('category_id', $id)->paginate(7);
但此代码仅显示类别 ID 帖子我想要类别和子类别的帖子
【问题讨论】:
-
请检查表结构的链接
-
尝试类似 Category::where(parent_id, 1)->with('post')
-
不,它没有帮助
-
我的代码不完整你需要通过laravel热切的laoding
-
定义类别模型中 parent_id 的 hasMany 关系到发布模型 category_id 字段