2017-04-20 20 views
0

モーダルリレーションを熱心にロードし、配列セレクタ['invoicePayments']を避ける方法はありますか?モデルインスタンスを使用したLaravel eager load modelの関係?

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); 
関連する問題