I don't understand how to create a Form with multiple select values in Laravel.
<?php $genre = array(
'Action' => 'Action',
'Biography' => 'Biography',
'Drama' => 'Drama',
'Crime' => 'Crime'
);
?>
{{ Form::label('genre', trans('main.genre')) }}
{{ Form::select('genre', $genre, array('Action'), array('multiple' => true, 'class' =>'form-control')); }}
From here if I select Action and Biography, only the last value (biography) gets saved into the "Genre" Field
If I change genre to genre[]
<?php $genre = array(
'Action' => 'Action',
'Biography' => 'Biography',
'Drama' => 'Drama',
'Crime' => 'Crime'
);
?>
{{ Form::label('genre', trans('main.genre')) }}
{{ Form::select('genre[]', $genre, array('Action'), array('multiple' => true, 'class' => 'form-control')); }}
I receive the error Parameter mismatch, pattern is a string while replacement is an array
I don't think you are declaring your multiple
correctly.
first off, completely forget the 2nd piece of code you posted. The first parameter of the Form::select
is the name and this is a string. By putting []
it's making it an array, so that's a non-starter.
Your field call should be:
{{ Form::select('genre', $genre, array('Action'), array('multiple', 'class' =>'form-control')); }}