Reputation: 711
I've created a form with multiple inputs, which are all behaving fine with the exception of the following:
{!! Form::open(['route' => ['changes.store'], 'class' => "was-validated"]) !!}
<div class="form-group">
<div class="row">
<div class="col-md-6 pt-3 bg-light">
<label for="options">Options:</label>
<select id="options" name="options" class="form-control" multiple>
@foreach ($options as $option)
<option value="{{ $option->id }}" selected>{{ $option->name }}</option>
@endforeach
</select >
</div>
</div>
</div>
<div class="row">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="submit" class="btn btn-success" type="button">
</div>
{!! Form::close() !!}
Option is just a collection of values that is being sent to the view from my model
$options = Option::all();
The form looks correct if I inspect it, but when I do
dd($request->all);
I get the last value as a string, eg "options" => "4"
, rather than some kind of array that I'd expect. Eg "options" => ["1", "2", "3", "4"]
Am I missing something here? All of the "options" values are selected, so I can't see why it's just the last one that's being passed to the controller.
Upvotes: 0
Views: 767
Reputation: 470
Updating the name of the input to include the array syntax will let the application know to pass over the full array and not just what the last selected option was.
<select id="options" name="options[]" class="form-control" multiple>
...
</select >
Upvotes: 1