Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Form::model binding Laravel with <select multiple>

I just discorvered that Form::model binding existed and I'm delighted with (it's wonderful). I tried it with text, email, and even select, every single time it worked.

My question is, will it work with a <select multiple>? If it does, how am I supposed to use it and what is the correct way to save an array in the database? (This may be awful but I concatenate all the options of the array with a separator and save it as text, I'm sure it's not the correct way to do it).

like image 868
Mathius17 Avatar asked May 23 '14 19:05

Mathius17


1 Answers

just like this :

Form::select('menus[]', $menus, null, array(
      'multiple' => true,
      'class' => 'form-control'
));

take a note :

param 1 : should be your field name (if want multiple add array tag aftrer field name e.g :menus[])

param 2 : list menu (array) e.g : array('value1' => 'text1', 'value2' => 'text2')

param 3 : selected values. (should be null because Form::model will perform automatically matching values from database. and make sure the field name has same with key data result from database)

param 4 : is property for element <select> you can add class, id, and etc..

like image 192
antoniputra Avatar answered Oct 12 '22 19:10

antoniputra