I'm using Maatwebsite\Excel to import a csv file to store new users in the DB. If i have already a record in DB with the same data it creates and error. How can i update the record if it exists ?
My import class is :
class UsersImport implements ToModel, WithCustomCsvSettings, WithHeadingRow
{
/**
* @param array $row
*
* @return \Illuminate\Database\Eloquent\Model|null
*/
public function model(array $row)
{
return new User([
'firstname' => $row['firstname'],
'lastname' => $row['lastname'],
'email' => $row['email'],
'password' => $row['pass'],
'created_at' => $row['registered'],
]);
}
public function getCsvSettings(): array
{
return [
'delimiter' => ","
];
}
}