我正在使用 hasManyThrough 关系。这两个表通过表 Table2 链接。
表 Table2 包含 id Table1 和 id Table3。
我们需要从 Table3 中获取数据,并在知道 table1_id 的情况下从 Table2 中获取其他数据。
我收到了来自 Table3 的值,但我无法从链接表 Table2 中获取其他数据。
Table1
id
Table2
id
table1_id
table2_id
data
Table3
id
info
知道 table1_id ,我从 Table3 获取信息值,但是如何从 Table2 获取数据值?
有桌子
用户模型是:
获取用户的汽车:
$user->cars获取枢轴:($car->pivot在示例中,user_id,car_id 将进入枢轴)据我所知,要在结果中添加更多枢轴列,请使用:->withPivot('pivot_name1', 'pivot_name2')在 belongsToMany 之后