拉维尔(Laravel)加入不在3个不同的桌子上工作
模型
Album::join('tracks', 'albums.track_id', '=', 'tracks.id')
->join('singers', 'tracks.singer_id', '=', 'singers.id')->get();
Snigers Table
id - int
name - string
跟踪表
id -int
name - string
singers_id - JSON // example["1","2"]
专辑table
id - int
name - string
tracks_id - JSON // example ["1","2"]
在这里首先Singers Table After table table ID多倍数下一个明矾表参考跟踪表ID也是数组。如何连接这三个表
Model
Album::join('tracks', 'albums.track_id', '=', 'tracks.id')
->join('singers', 'tracks.singer_id', '=', 'singers.id')->get();
Snigers table
id - int
name - string
Tracks table
id -int
name - string
singers_id - JSON // example["1","2"]
Album table
id - int
name - string
tracks_id - JSON // example ["1","2"]
here first singers table after track table reference array of id multiple and next alums table reference track table id is also array.how to joins this three table
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无需在此处使用加入,如果您有一个枢轴表,这就是您可以做的:
在模型中,您可以简单地创建这样的关系:
pream
模型:然后调用它在您的控制器中。
COMPORCONTROLLER.PHP
这将简单地使用属于相册ID 1的曲目和歌手获取所有记录。
There's no need to use joins here, if you have a pivot table for these, here's what you can simply do:
In your models you can simply create a relation like this:
Album
Model:and then call it in your controller.
AlbumController.php
This will simply fetch all the records with Tracks and Singers that belong to Album id 1.