扫码关注官方订阅号
我有三个表文章表
关系表
分类表
其中关系表当中的object_id对应文章表的idterm_taxonomy_id对应分类表的term_id
请我我如何使用eloquent通过多对多的方式获取文章表和分类表并且一同返回?
ringa_lee
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();
参考:https://segmentfault.com/q/10...,使用with
RTFMhttps://laravel-china.org/doc...
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
扫描下载App
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
参考:https://segmentfault.com/q/10...,使用with
RTFMhttps://laravel-china.org/doc...