How do I pass multiple variables to the same view? Something like:
return "view('textos.index', ['textos1' => $textos1, 'textos2' => $textos2, 'textos3' => $textos3]);"
How do I pass multiple variables to the same view? Something like:
return "view('textos.index', ['textos1' => $textos1, 'textos2' => $textos2, 'textos3' => $textos3]);"
It's just like this:
return view('textos.index', [
'texto1' => $texto1,
'texto2' => $texto2,
'texto3' => $texto3
]);
And in the view you access it like this:
<div>
<p>{{$texto1}}</p>
<p>{{$texto2}}</p>
<p>{{$texto3}}</p>
</div>
The only thing wrong here is that you put quotation marks around, so you were returning String
In your case, you can also use the compact
function.
This function captures the local variable names and creates an associative array with the appropriate values.
So, it could be done like this:
$texto1 = 1;
$texto2 = 2;
$text3 = 3;
return view('home', compact('texto1', 'texto2', 'texto3'));