php – 如何在刀片中的Laravel关系函数中传递参数?

前端之家收集整理的这篇文章主要介绍了php – 如何在刀片中的Laravel关系函数中传递参数?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Student.PHP

它有很多费用

class student extends Model{
    public function fees($round){
        return $this->hasMany(fee::class)->where('payment_round','=',$round);
    }
}

Fee.blade.PHP

@foreach($student->fees("parameter") as $fee)
    {{$fee->myproperty}}
@endforeach

我如何将参数传递给$student->费用(“参数”)?

解决方法

尝试类似的东西:

@foreach($student->fees($parameter)->get() as $fee)
   {{ $fee->myproperty }}
@endforeach

我认为你把相关模型费用的收集与查询构造函数费用混淆了().

猜你在找的Laravel相关文章