I need to pass selectbox selected data to Laravel Controller.
But It always return null.
What is wrong in my code, Thanks You.
<td class="mr-3"> <select class="form-control" name="section[]" id="section" value=""> <option>Select Section</option> @foreach ($sections as $key => $value) {{ $value }} <option value="{{ $key }}" {{ ( $key == $selectedID) ? 'selected' : '' }}> {{ $value }} </option> @endforeach </select> </td>In my Controller:
public function store(Request $request) { foreach($request->input('sections') as $key => $value){ $data['value'] = $key; } dd ($data['value']); // <- Returns Null !
Add a comment
|
1 Answer
use the name with out []
<select class="form-control" name="section" id="section" >
in the controller
$data['value'] = $request->input('sections');
if you want multiple selection
<select multiple="multiple" name="sections[]" id="sections">
in the controller
foreach($request->sections as $key ){
$data['value'] []= $key;
}