Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

272
Views
How can you get selected dual list box values in Laravel

I have a dual list box in my Laravel form and I want to get those values that are taken over to the right side. Currently, only 1 value gets taken over, but if a user picks 3 values over, I would like all 3 values to be stored in the database. Is there any way to do this?

My controller:

 public function storesurvey(Request $request)
    {          
        $energy = new Customer();
        $energy->rank1 = $request->input('rank1');
        $energy->comments = $request->input('comments');
        $energy->save();
        return redirect('/survey')->with('success', 'data added');
    }

My view:

<div class="container">                
                  <div class="jp-multiselect">
                      <div class="from-panel">
                          <select name="from[]" class="form-control" size="8" multiple="multiple">
                              <option value="1">Item 1</option>
                              <option value="2">Item 2</option>
                              <option value="3">Item 3</option>
                              <option value="4">Item 4</option>
                              <option value="5">Item 5</option>
                          </select>
                      </div>
                      <div class="move-panel">
                          <button type="button" class="btn-move-all-right btn-primary"></button>
                          <button type="button" class="btn-move-selected-right"></button>
                          <button type="button" class="btn-move-all-left"></button>
                          <button type="button" class="btn-move-selected-left"></button>
                      </div>
                      <div class="to-panel">
                          <select name="rank1" class="form-control" size="8" multiple="multiple">
                           
                          </select>
                      </div>
                      
                  </div>
                  <script>
                      $(".jp-multiselect").jQueryMultiSelection();
                  </script>
                  <hr />
                  <!-- 2 -->                
              </div>

Could someone explain why only one value gets taken over and how I can send all value that are present on the right.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

To send multiple value from a select input (or checkboxs having the same name) you need to name the input with [] like you did in the select form[]

<select name="rank1[]" class="form-control" size="8" multiple="multiple">

Then in your controller, you need to treat it as an array.

Here i used a json incode to convert all rank1 values into a single value string of format json.

public function storesurvey(Request $request)
    {          
        $energy = new Customer();
        $energy->rank1 = json_encode($request->input('rank1'));
        $energy->comments = $request->input('comments');
        $energy->save();
        return redirect('/survey')->with('success', 'data added');
    }

Other Solution

You can also make this auto using Casting

-Customer.php

class Customer .....
{
    protected $casts = [
        'rank1' => 'array'
    ];
    ....
}

Then in your controller, you can assign an array to the attribute rank1 directly without converting it

public function storesurvey(Request $request)
{          
    $energy = new Customer();
    $energy->rank1 = $request->input('rank1');
    $energy->comments = $request->input('comments');
    $energy->save();
    return redirect('/survey')->with('success', 'data added');
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!