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-> fees(“参数”)?
尝试类似的东西:
@foreach($student->fees($parameter)->get() as $fee)
{{ $fee->myproperty }}
@endforeach
我认为你把相关模型fees
的集合与查询构造函数fees()
混淆了。
您可以保持关系尽可能简单,并添加第二个方法,使用它来获取所需的数据:
<?php
class student extends Model{
public function fees(){
return $this->hasMany(fee::class);
}
public function getFeeByRound($round)
{
return $this->fees()->where('payment_round','=',$round)->get();
}
}
然后你可以用它作为:
@foreach($student->getFeeByRound($parameter) as $fee)
{{ $fee->myproperty }}
@endforeach