Utilize App\Categoria::orderBy('nome')->get()
, although this is not a good recommendation. Should come the die ready to View
of Controller
, but there’s the way it should be.
<div class="form-group">
<label for="nome">Categoria do Produto</label>
<select id="categoria_id" name="categoria_id" class="form-control">
<option value="">Selecione</option>
@foreach (App\Categoria::orderBy('nome')->get() as $categoria)
<option value="{{ $categoria->id }}">{{ $categoria->nome }}</option>
@endforeach
</select>
</div>
Recommending
The ideal practice would be to send only the data ready for your View
:
Controller
public function exibe()
{
$data['categories'] = \App\Categoria::orderBy('nome')->get();
return view('view1', $data);
}
View
<div class="form-group">
<label for="nome">Categoria do Produto</label>
<select id="categoria_id" name="categoria_id" class="form-control">
<option value="">Selecione</option>
@foreach ($categories as $categoria)
<option value="{{ $categoria->id }}">{{ $categoria->nome }}</option>
@endforeach
</select>
</div>
This is an example, dummy data
References:
Perfect, but this coming duplicate has some article or some reading tip where I get more information in my creations
– leonardo silva
@leonardosilva duplicates what? because this code refers to what is in your database, your database has duplicated items?
– novic
@leonardosilva and then the problem was solved?
– novic
nor could friend, I put aside for a while, to return to my initial projects, but today I gave continuity to them.
– leonardo silva