gpt4 book ai didi

php - Laravel 使用模型实例急切加载模型关系?

转载 作者:行者123 更新时间:2023-12-02 20:47:50 24 4
gpt4 key购买 nike

是否有其他方法可以立即加载模态关系并避免使用 ['invoicePayments'] 数组选择器?

效果:

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

现在的主要原因是因为我使用的是模型绑定(bind)注入(inject),所以我的方法只是 function getInvoicePayments(Payment $ payment) 但我觉得这个数组选择是错误的,但我想不出其他解决方案吗?有什么想法吗?

最佳答案

以下所有内容应该是等效的:

$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);

关于php - Laravel 使用模型实例急切加载模型关系?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43530643/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com