Hi @noblemfd
Can you select the unique record by the employee_code AND dept_code columns or is that not possible?
If so, you could change your code to:
$employee = HrEmployee::updateOrCreate([
'employee_code' => $clientdata['staff_id'],
'dept_code' => $clientdata['department_id']
],
[
'first_name' => $clientdata['first_name'],
'last_name' => $clientdata['last_name'],
'other_name' => $clientdata['middle_name']
]);
If not I'm afraid you're going to be a little more verbose:
$employee = HrEmployee::firstOrNew([
'employee_code' => $clientdata['staff_id']
]);
$employee->fill([
'first_name' => $clientdata['first_name'],
'last_name' => $clientdata['last_name'],
'other_name' => $clientdata['middle_name']
]);
if (! $employee->exists) {
$employee->dept_code = $clientdata['department_id'];
}
$employee->save();