這裏是我的表格。獲取Laravel中超過2個連接表的數據和雄辯
╔════════════╤═╤══════════╤═╤═══════╗
║ Insurances │ │ Devices │ │ Brands║
╠════════════╪═╪══════════╪═╪═══════╣
║ id │ │ id │ │ id ║
╟────────────┼─┼──────────┼─┼───────╢
║ IMEI │ │ type │ │ name ║
╟────────────┼─┼──────────┼─┼───────╢
║ device_id │ │ name │ │ ║
╟────────────┼─┼──────────┼─┼───────╢
║ user_id │ │ brand_id │ │ ║
╚════════════╧═╧══════════╧═╧═══════╝
現在我想告訴在一個表中的結果數據,如
╔══════╤════════════╤═════════════╤══════════════╤═════════╗
║ IMEI │ brand_name │ device_name │ device_price │ user_id ║
╚══════╧════════════╧═════════════╧══════════════╧═════════╝
試想一下,如果它是AJAX和我有數據發送到視圖之前加入的表。我已經定義了模型中的關係。但與with()
方法我只能在同一時間調用2,但我不知道如何在視圖中調用它們。
是否有反正不使用普通DB::class
只是用口才?
您是否建立了關係? – Andrius
@Andrius是的,我有。 –
好的。問題是如何用保險解析Device對象(我懷疑是一對一關係)還是品牌(又是一對一)?很明顯,你需要在控制器或模型中進行解析,而不是像前面提到的那樣進行解析。 – Andrius