2017-04-20 120 views
0

有沒有其他辦法可以加載模式關係並避免有['invoicePayments']數組選擇器?使用模型實例的Laravel渴望加載模型關係?

FX:

$payment->load(['invoice.source', 'invoice.user']) 
      ->getRelations()['invoicePayments']; 

主要的原因是這樣的,現在是因爲我使用模型綁定注射,所以我的方法就是function getInvoicePayments(Payment $payment),但我覺得這個陣列選擇是錯誤的,但我不能想想在其他任何解決方案嗎?有任何想法嗎?

回答

1

下面的一切應該是等價的:

$one = $payment->load(['invoice.source', 'invoice.user'])->getRelations()['invoicePayments']; 

$two = $payment->load(['invoice.source', 'invoice.user'])->getRelation('invoicePayments'); 

$thr = $payment->load(['invoice.source', 'invoice.user'])->invoicePayments; 

dd($one, $two, $thr);