Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

276
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda