I am new in laravel.First I have I have inserted a form data into database .Then I have fetched this data into an array. Then I inserted this data into a new database. When every time insert form data, In my second database all data inserted multiple time.My code is given below:
foreach($result as $res) {
$res1 = UserList::firstOrCreate($res);
}
Here is my array. If same data is in database, I only want update the array new value into database
The method you want to use is updateOrCreate
Model::updateOrCreate(
['needle' => $value],
['field1' => 'value1', 'field2' => 'value2']
);
Hope this help.