mercredi 22 janvier 2020

Undefined offset even submitting foreach loop into database

I have the following foreach in my view that i am trying to submit and store into my database. Without any luck. When i try to submit using the code from my controller is returns an error Undefined offset: 70.

This is the controller code:

foreach ($request->marketers as $key => $value){
           $str_explode = explode("|",$value);  
           $answer = new Retirement();
           $answer->user_id = $str_explode[1];
           $answer->marketer =  $value;
           $answer->amount = $request->amount[$key];


           $answer-> save();


      }

This is my view file with the foreach loop:

@foreach ($request as $item)
    <tbody>
        <tr>
        <td  class="idweek1"> <input type="text" id="userid" name="userid" class="form-control" value=""> </td>
        <td><input type="text" id="marketers" name="marketers[]" class="form-control" value="">  </td>
        <td><input type="text" id="amount" name="amount[]" class="form-control" value=""> </td>
        <!-- <td></td> -->
        <td><input type="text" id="mar1id" class="form-control" value="">   </td> 
        </tr>
    </tbody>
@endforeach


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire