0
  • I need to pass selectbox selected data to Laravel Controller.

  • But It always return null.

  • What is wrong in my code, Thanks You.

    <td class="mr-3">                                           
      <select class="form-control" name="section[]" id="section" value="">
    <option>Select Section</option>
    
    @foreach ($sections as $key => $value) {{ $value }}
     <option value="{{ $key }}" {{ ( $key == $selectedID) ? 
         'selected' : '' }}>
    
     {{ $value }}
      </option>
     @endforeach
     </select>
     </td>
    
  • In my Controller:

     public function store(Request $request)
     {
      foreach($request->input('sections') as $key => $value){
      $data['value'] = $key;
    }
       dd ($data['value']);  // <- Returns Null !
    

1 Answer 1

1

use the name with out []

<select class="form-control" name="section" id="section" >

in the controller

  $data['value'] = $request->input('sections'); 

if you want multiple selection

      <select  multiple="multiple" name="sections[]" id="sections">

in the controller

       foreach($request->sections as $key ){
           $data['value'] []= $key;
              }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.