Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在叶片内传递Laravel关系函数中的参数?_Php_Laravel 5_Laravel Blade_Laravel 5.7 - Fatal编程技术网

Php 如何在叶片内传递Laravel关系函数中的参数?

Php 如何在叶片内传递Laravel关系函数中的参数?,php,laravel-5,laravel-blade,laravel-5.7,Php,Laravel 5,Laravel Blade,Laravel 5.7,Student.php @foreach($student->fees("parameter") as $fee) {{$fee->myproperty}} @endforeach 它有很多费用 class student extends Model{ public function fees($round){ return $this->hasMany(fee::class)->where('payment_roun

Student.php

@foreach($student->fees("parameter") as $fee)
    {{$fee->myproperty}}
@endforeach
它有很多费用

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

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

您可以保持尽可能简单的关系,并添加第二种方法,使用该方法获取所需数据:

<?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();
    }

}

你为什么不试试,告诉我们你犯了什么错误?e、 g
$var='Hello'@foreach($student->fees($var)as$fee){{{$fee->myproperty}}@endforeach
它不会显示任何错误消息。它只是空的