【问题标题】:how to pass value from blade to controller in laravel? [closed]如何在 laravel 中将值从刀片传递到控制器? [关闭]
【发布时间】:2020-12-23 02:20:29
【问题描述】:

我是 laravel 的新手,请您在以下情况下帮助我, 我有一个接受三个参数的函数

public function myfunction (Request $request)
{
    $first=$request->first;
$second=$request->second;
$third=$request->third;
{some calculation here }
return view('report/myrepo1,.......)}

现在我有刀片,我们在每个循环中都有类似这样的其他 $ 变量

@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)}}

知道如何解决此类问题 谢谢

【问题讨论】:

标签: php laravel eloquent laravel-blade query-builder


【解决方案1】:

你必须在你的刀片文件中调用控制器函数 例如:

{{\App\TestController::TestFunction($item->id)}}

【讨论】:

    【解决方案2】:

    您可以使用服务提供者内部的 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-13
      • 2017-07-31
      • 2017-09-03
      • 2016-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-29
      相关资源
      最近更新 更多