No. It is not true
Jan 17, 2024
3
Level 1
create method in laravel
is that true that when create method is being called within a loop, each call to create, overwrites the previous one, resulting in only the last record being saved? I have the collection ofdata like this: {{date=>17:00:04, response_time=> 465, server_referer=> iran, site_name=>x}, {date=>17:30:13, response_time=> 0, server_referer=> iran, site_name=>x}}, and I want to save it in a table, I have used this lines of code but just the last one saves in the table, it seems that it is updated row!!
if (!$responsetimeDashboard->isEmpty()) {
foreach ($responsetimeDashboard as $dashboard) {
try {
ModelsResponsetimeData::create (
[
'type' => 'Dashboard',
'site_name' => $dashboard->site_name,
'response_time' => $dashboard->response_time,
'server_referer' => $dashboard->server_referer,
'date' => $dashboard->date,
]
);
} catch (\Exception $e) {
echo $e->getMessage("Something went wrong");
}
}
}
Level 80
@sahar_mkr Try removing the useless try/catch block.
Please or to participate in this conversation.