1
我有標題爲中間表hasManyThrough - 不返回正確的數據
app_services
它包括以下欄:
- app_service_id(PK)
- APP_ID(FK )
- service_id(FK)
最後的表是服務表:
服務
- 的service_id(PK)
- 服務名
- service_icon
我想上app_services一個hasManyThrough 。但是,它的返回錯誤的結果..
對於APP_ID = 1它有1 & 3.業務ID,但它返回回的service_id的PF 1 & 4.
在我app_model我定義的關係如下:
public function services()
{
return $this->hasManyThrough(
'App\Service', 'App\AppService',
'service_id', 'service_id', 'app_id'
);
}
現在看起來對我有好處嗎?有人會檢查它是否正確。
謝謝!
嗨這種關係,所以你會把這些放在每個模型上?或者在應用模型中的一個模型 – StuBlackett
中,您必須使用decklare服務功能,並且在服務模型中,您可以聲明應用模型 –
以獲取更多信息,您可以訪問http://laraveldaily.com/pivot-tables-and-many-to-many -relationships/ –