2017-04-20 129 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);