-1

I am new in laravel, could you please help me in below situation, i have a function which takes three arguments

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

now i have blade where we have for each loop of some other $variable like this

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

any idea how to solve this kind of problem thanks

ismail
  • 5
  • 5
  • see this answer use any one method as per your situation https://stackoverflow.com/questions/35332784/how-to-call-a-controller-function-inside-a-view-in-laravel-5 – bhucho Sep 03 '20 at 19:44
  • your method does not take 3 arguments by the way, it takes one and its a Request – lagbox Sep 03 '20 at 19:55
  • but i like to pass three arguments – ismail Sep 03 '20 at 22:35
  • 1
    Does this answer your question? [How to call a controller function inside a view in laravel 5](https://stackoverflow.com/questions/35332784/how-to-call-a-controller-function-inside-a-view-in-laravel-5) – Daan Seuntjens Sep 04 '20 at 10:08

2 Answers2

0

you must call Controller function in your blade file as an example:

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

You can define a custom blade directive using Blade:: facade inside a service provider i.e. app\Providers\AppServiceProvider.php something like below:

In boot method of your 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;
});

In your blade file

@foreach($var as $v)
    <td>{{ @myfunction($v->first, $v->second, $v->third) }} </td>
@endforeach
Manjeet Barnala
  • 2,975
  • 1
  • 10
  • 20