还有其他方法可以加载模态关系并避免使用['invoicePayments']
数组选择器吗?
fx:
$payment->load(['invoice.source', 'invoice.user'])
->getRelations()['invoicePayments'];
现在的主要原因是因为我正在使用模型绑定注入,所以我的方法只是function getInvoicePayments(Payment $payment)
但我觉得这个数组选择是错误的,但我想不出任何其他解决方案它?任何想法?
答案 0 :(得分:3)
以下所有内容均应相同:
$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);