Laravel hasManyThrough 只返回相关模型的数据

问题描述 投票:0回答:0

我有以下型号

Member
    -id
    -full_name
    -others...

AllowanceBill
    -id
    -others...

Payment
    -allowance_bill_id
    -member_id
    -total_amount
    -payable_amount

我在 AllowanceBill 模型上使用这种关系

public function members(){
    return $this->hasManyThrough(
        Member::class,
        Payment::class,
        'allowance_bill_id',
        'id',
        'id',
        'member_id'
    );
}

我想显示一张特定账单的表格,比方说 Bill#2 这种格式

会员ID、全名、总金额、应付金额

但是在 AllowanceBillController 的 show() 回调中使用它

$allowanceBill->members()->get();

返回所有付款,而不仅仅是特定于 bill#2 的付款

知道为什么它不起作用吗?

mysql laravel has-many-through
© www.soinside.com 2019 - 2024. All rights reserved.