我是laravel的新手,请在以下情况下为我提供帮助, 我有一个需要三个参数的函数
public function myfunction (Request $request)
{
$first=$request->first;
$second=$request->second;
$third=$request->third;
{some calculation here }
return view('report/myrepo1,.......)}
现在我有刀片,每个其他这样的$ variable这样的循环都位于
@foreach($var as $v)
<tr>{{<td>$v->first}}</td>
<td>{{$v->second}}</td>
<td>{{$v->third}}</td>
<td>{{ ????? //How to cal the function which i wrote in controller }}
//if i am doing calling a function as we do in C or C++ it show error}}
//like this {{myfunction($value->first,$value->second,$value->third)}}
任何想法如何解决这类问题 谢谢
答案 0 :(得分:0)
您必须在刀片文件中调用Controller函数 例如:
{{\App\TestController::TestFunction($item->id)}}
答案 1 :(得分:0)
您可以在服务提供商内部使用Blade :: facade定义自定义的Blade指令,即app\Providers\AppServiceProvider.php
如下所示:
在您的app\Providers\AppServiceProvider.php
的启动方法中
//Blade directive to myfunction.
Blade::directive('myfunction', function ($a1, $a2, $a3) {
//Do calculations you want here and return back..
return $a1 + $a2 + $a3;
});
在刀片文件中
@foreach($var as $v)
<td>{{ @myfunction($v->first, $v->second, $v->third) }} </td>
@endforeach