mercredi 15 novembre 2017

For loop is not working correctly in Laravel Controller

I am saving some input data into database. Using for loop I am trying to save the input data in different rows.

for ($i=0; $i < $day ; $i++) { 
    $activity->event_id = $request->event_id;
    $activity->created_by = $id;
    $activity->index = $request->index[$i];
    $activity->activity_title = $request->activity_title[$i];
    $activity->activity_details = $request->activity_details[$i];

    $activity->save();
}

The problem is, it only saves the last value. Suppose if day = 2 it saves the information of the second index of my arrays. Ignores the first index value. Where am I doing wrong?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2z2RXwG
via IFTTT

Aucun commentaire:

Enregistrer un commentaire