I'm trying to find a way to call a method from within my class file inside a blade file. foo()
uses the $item
variable from the foreach loop. Since I'm looping inside the blade file, I'm unable, or rather, it's bad practise, to call a controller method inside a view, or so I've heard.
MyController
public function getData() {
$data = DB::paginate(10);
return view('view', ['data' => $data]);
}
public function foo($var) {
//do something with $var
return $var
}
view.blade.php
@foreach ($data as $item)
<td>{{$item->key}}</td>
<td>{{ //myController::foo($item) is Essentially the output I need }} </td>
@endforeach
Since $item
is generated in the foreach
(which is inside the view), I don't know how to call method before it's past to the view in the return statement.
Any suggestions?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire