How to get all values from a multiple select field in laravel controller

Udhayan Nair

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).

MekjkrhG

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.

edited at
0

Comments

0 comments
Login to comment

Related

How to get all values from Laravel controller to index using JavaScript?

How to get all selected values from <select multiple=multiple>?

How to get all unselected values from SELECT (Multiple) jQuery | JavaScript

Get multiple values from the same select dropdown form field in React

How to get all values from multiple options

How to get multiple values from a model field into a form choice field?

How to select multiple values in selectize plugin from controller

How to take values from multiple options of select input field

Get all possible values of a select field

laravel, how to select with all values

How to get all selected values of a multiple select box?

Laravel 8: In Controller - how to get values array from model object

Can't receive all form field values in controller from blade. Laravel

How do I get all the values of a particular field from a store?

How to get multiple selected values of select box in laravel?

How get Multiple Checkbox value in Controller submitted from the form in laravel?

Meteor (blaze) how to find all values from a select multiple

How to get the values of a select multiple?

How to get the selected values of multiple select box in a text field in. I am using select js library

How to get multiple selected values from select box in JSP?

How do I get values from multiple vue select instances?

How to get multiple attribute values from select options in angular

How to get multiple values from tail.select?

How to select multiple values ​in one field?

Elasticsearch Get the values of a field from all the documents

How to get all values of one key from laravel multidimensional array

XmlDocument - How to get all values from multiple nodes

How to select and get data from multiple tables (Laravel)

how i set angulrajs checkbox ng-model to multiple select in laravel foreach and pass values to angularjs controller