Php 如何在laravel中将值从刀片传递给控制器?
我是拉雷维尔的新手,在下面的情况下你能帮我吗, 我有一个函数,它有三个参数Php 如何在laravel中将值从刀片传递给控制器?,php,laravel,eloquent,laravel-blade,query-builder,Php,Laravel,Eloquent,Laravel Blade,Query Builder,我是拉雷维尔的新手,在下面的情况下你能帮我吗, 我有一个函数,它有三个参数 public function myfunction (Request $request) { $first=$request->first; $second=$request->second; $third=$request->third; {some calculation here } return view('report/myrepo1,.......)} 现在我有了blade,每个
public function myfunction (Request $request)
{
$first=$request->first;
$second=$request->second;
$third=$request->third;
{some calculation here }
return view('report/myrepo1,.......)}
现在我有了blade,每个循环都有一些其他的$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)}}
@foreach($var为$v)
{{$v->first}
{{$v->second}
{{$v->third}
{{?????//如何调用我在controller}中编写的函数
//如果我正在调用函数,如在C或C++中所示,则显示错误}
//像这样{{myfunction($value->first$value->second$value->third)}
你知道怎么解决这种问题吗
谢谢您必须在刀片文件中调用控制器函数 例如:
{{\App\TestController::TestFunction($item->id)}}
您可以在服务提供商内部使用blade::facade定义自定义刀片指令,即
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
@foreach($var为$v)
{{@myfunction($v->first,$v->second,$v->third)}
@endforeach
查看此答案根据您的情况使用任意一种方法顺便说一句,您的方法不需要三个参数,它需要一个参数和一个请求,但我想传递三个参数这能回答您的问题吗?