Update data into table from dynamically created input field

别说谁变了你拦得住时间么 提交于 2019-12-01 23:55:43

For updation try this code

$itinerary = Itinerary::find($tour_id);
$itinerary->plan = $temp_itinerary[$i];        
$itinerary->day = $temp_day[$i];
$itinerary->save();

The way you are using is to insert/create new records. To update you can use.

Itinerary::find($tour_id)->update(
   ['column_name'=> value]
);

Where find method takes a primary key of the table.

This will update your existing record. You can update as many columns as you want just pass in array update takes. You can also use save method as mentioned in other answer.

Check Laravel Update Eloquent

EDIT

$iterneary = Itenerary::where('tour_id', $tour_id)->first();

Now you can update this iterneary object to whatever you want.

this is how i did it. First saved all the tours in $tours[] array.

foreach($tours as $tour) {
        $itinerary->tour()->updateOrCreate(['id'=> $tour['id']],$tour);
    }

updateOrCreate because you may need to add new tours while updating. I know this doesnt answer your issue exactly but this could atleast give you an idea.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!