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(“ parameter”)?
答案 0 :(得分:1)
尝试类似的事情:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="checkbox" id="ch" />
<input type="text" id="myinp" />
我认为您已经将相关模型@foreach($student->fees($parameter)->get() as $fee)
{{ $fee->myproperty }}
@endforeach
与查询构造函数fees
混淆了。
答案 1 :(得分:0)
您可以保持关系尽可能简单,并添加第二种方法来获取所需的数据:
<?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