0
I have a view called form where I need it to appear, in the select field, the States(UF) coming from Mysql. I have the EstadoController
where in the index method I do the listing using all. Now, I want this listing to appear in the form view whose route is: Route::get('/formulario', 'FormularioController@create');
To EstadoController
is like this:
public function index(Estado $estado){
$retornoAllEstado = $estado->all();
return view('painel-adm.formulario', compact('retornoAllEstado'));
}
But when I foreach in the view form, I come across error:
<select class="custom-select" name="qpae_uf_rg">
@foreach($retornoAllEstado as $estado)
<option value="1">{{$estado->uf}}</option>
@endforeach
</select>
Error generated: Undefined variable: retornoAllEstado
...
Formulariocontroller.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
/* Usando a model Formulario */
use App\Models\Painel\Formulario;
class FormularioController extends Controller
{
private $formulario;
public function __construct(Formulario $formulario)
{
$this->formulario = $formulario;
}
public function index()
{
}
public function create()
{
return view('painel-adm.formulario');
}
public function store(Request $request)
{
}
public function show($id)
{
}
public function edit($id)
{
}
public function update(Request $request, $id)
{
}
public function destroy($id)
{
}
}
formulario.blade.php
<div class="form-group col-md-1">
<label>UF</label>
<select class="custom-select" name="uf">
@foreach($retornoAllEstado as $estado)
<option value="1">{{$estado->uf}}</option>
@endforeach
</select>
</div>
executes a
dd($retornoAllEstado);
after the line you get all the records, and tell me the result.– Bulfaitelo
Well, returned an array with the 27 items, but for me to see the result without error, I had to create a route Route::get('/states-list', 'Estadocontroller@index'); But now you need these UF listings to appear in my form view.
– Barraviera
Refreshes the question and puts the controller that returns from that form and the view. .
– Bulfaitelo
I don’t know if I was very clear. When I type in the browser /states-list opens the.php status view and correctly appears the UF listing. Now, I need this listing to appear in the view formulario.blade.php
– Barraviera
Run a test on the answer I gave and see if that’s it.
– Bulfaitelo