Load a Combobox with Selected Value

Asked

Viewed 634 times

1

I need to edit an equipment register that has multiple combos and when you click edit load the select already with the selected selected.

I thought Laravel automatically identified, but it doesn’t look like.

I charge making one foreach in view Edit(form). How to do this ?

  • You have the Laravelcollective package installed in your project ?

  • No. I don’t even know.

1 answer

0

It would be nice for you to install the Laravel Collective.

You will have access to class Form.

Example of combobox filled with database data:

Controller

$users = User::orderBy('nome')
->get()
->lists('nome', 'id');

return view('backend.cadastro')->with('users', $users');

View

{!! Form::select('usuarios', $users, VALOR_SELECIONADO) !!}

Parameters:: (NAME, ARRAY_DE_VALORES, VALUE DEFAULT, ARRAY)

Where it is written above VALOR_SELECIONADO is where you will put the ID of the value that has to come selected in combobox. Then you adapt to your case.

  • What are users? The table?

  • This combo I want to put already selected is a relationship. I have to do the relationship before?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.