我有三个表
文章表
关系表
分类表
其中关系表当中的object_id对应文章表的id
term_taxonomy_id对应分类表的term_id
请我我如何使用eloquent通过多对多的方式获取文章表和分类表并且一同返回?
我有三个表
文章表
关系表
分类表
其中关系表当中的object_id对应文章表的id
term_taxonomy_id对应分类表的term_id
请我我如何使用eloquent通过多对多的方式获取文章表和分类表并且一同返回?
<code class="php">class Article extends Model{
public function category()
{
return $this->belongsToMany('App\Categorys', 'relations', 'term_taxonomy_id', 'object_id');
}
}
$res = Article::with('category')->where('id', $id)->get();
</code>
参考:https://segmentfault.com/q/10...,使用with
RTFMhttps://laravel-china.org/doc...
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号