How to gett selected values from a multiple select form in Laravel

0 votes

For generating a drop-down list with an item selected by default, the following is done:

echo Form::select('size', array('L' => 'Large', 'M' => 'Medium', 'S' => 'Small'), 'S');

So I generated a drop-down list that has more than one item selected by default, in the following way:

echo Form::select('size', array('L' => 'Large', 'M' => 'Medium', 'S' => 'Small'), array('S', 'M'), array('multiple'));

But how do I get the more than one selected values?

Input::get('size') returns only the last selected string.

Oct 21, 2020 in Laravel by kartik
• 37,520 points
7,394 views

1 answer to this question.

0 votes

Hello @kartik,

First, if you want to have multiple item selected by default, you have to give an array of values as 3rd parameter, not a simple value.

Example:

Form::select('size', array('L' => 'Large', 'M' => 'Medium', 'S' => 'Small'), array('S', 'M'), array('multiple'));

should show the select with S and M selected.

For the second point, you should try to give a name like size[] instead of size, it could be solve the problem (because your posted select is not a simple value, its an array of values)

Hope it helps!!

answered Oct 21, 2020 by Niroj
• 82,840 points

Related Questions In Laravel

0 votes
1 answer

How to chunk results from a custom query in Laravel

Hello @kartik, Try something like this: <?php $max = 100; $total ...READ MORE

answered Dec 7, 2020 in Laravel by Niroj
• 82,840 points
2,301 views
0 votes
1 answer

How to mock a static facade methods in Laravel?

Hey, Facades provide a "static" interface to classes ...READ MORE

answered Mar 19, 2020 in Laravel by Niroj
• 82,840 points
6,561 views
0 votes
1 answer

.How to turn off CSRF protection for a particular route in Laravel?

Hey, We can add that particular URL or ...READ MORE

answered Mar 24, 2020 in Laravel by Niroj
• 82,840 points
4,237 views
0 votes
1 answer

How to make a constant and use globally in laravel?

Hii, You can create a constants.php page in config folder ...READ MORE

answered Mar 24, 2020 in Laravel by Niroj
• 82,840 points
4,075 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
23,044 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
3,009 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
2,932 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
44,836 views
0 votes
1 answer

How to select all column name from a table in laravel?

You can get all columns name by ...READ MORE

answered Dec 2, 2020 in Laravel by Niroj
• 82,840 points
6,464 views
0 votes
1 answer

How to select year and month from the created_at attributes of database table in laravel 5.1?

Hello @kartik, There are date helpers available in ...READ MORE

answered Sep 30, 2020 in Laravel by Niroj
• 82,840 points
15,464 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP