'Multiple select dropdown in laravel
Here is my code in the view, I want to display a dropdown that contains the selected data in an edit view.
{{Form::select('Select_targets[]', $_targets,Input::old('Select_target', $profile->Target_idTarget-1), array('multiple' => true))}}
I tried this code but it just displays one selected value. Please I need your help! Thanks in advance
Solution 1:[1]
I think you have an error around your old input and default values for the dropdown. Here is a stripped down example that does work:
Controller:
//current selected
$target = 3;
/array with options
$targets[1] = 'target 1';
$targets[2] = 'target 2';
$targets[3] = 'target 3';
return View::make('form')->with('targets',$targets)->with('target',$target);
View:
{{ Form::open() }}
{{ Form::select('targets[]', $targets, Request::old('targets') ? Request::old('targets') : $target, array('multiple' => true)); }}
{{ Form::submit('send') }}
{{ Form::close() }}
Solution 2:[2]
use wherein method of laravel incase you want to take all the option as query from request
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Björn |
Solution 2 | Keshab Bhattarai |