Basically, in my blade.php file or html file, I have a multiple select field. What I'm trying to do is get all selected field's ID and return it to my controller. How would I go about to do this?
Multiple Select in blade.php;
<div class="form-group">
<label class="col-xs-12" for="users">Select User</label>
<div class="col-sm-9">
<select class="form-control" id="users" name="users" size="10" multiple="">
@foreach($admin as $a)
<option value="{{$r->id}}">{{$a->fullname}}</option>
@endforeach
</select>
</div>
</div>
Controller that sends data;
public function assignRole() {
$role = Role::all();
$admin = Admin::all();
return View::make("assignRole", compact('role', 'admin'));
}
Controller that retrieves data;
public function assignNewRole(Request $request) {
$data = $request->all();
dd($data);
return redirect()->route('role')->with('success', 'Successfully assigned role.');
}
I'm trying to see what I get in my "dd", but what i get now is;
array:3 [▼
"_token" => "ongoBbjBaOXJrPleNSdYPsr8aJlb6CLUxHHkHKoP"
"role" => "1"
"users" => "2"
]
What i would want is maybe, "users" => "1", "3", "17". (a list of all the selected user id's).
Change name=users
to name=users[]
<select class="form-control" id="users" name="users[]" size="10" multiple="multiple">
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments