From 40767d2117424a3df9562b92f4fde90a52826617 Mon Sep 17 00:00:00 2001 From: Ray1111-aa Date: Wed, 28 Oct 2026 16:05:31 +0700 Subject: [PATCH] fix(migration): use DB query builder instead of User model in sync_security_guards to avoid missing deleted_at column --- ...ync_security_guards_to_employees_table.php | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/database/migrations/2026_10_28_083500_sync_security_guards_to_employees_table.php b/database/migrations/2026_10_28_083500_sync_security_guards_to_employees_table.php index 9446f23..95398e1 100644 --- a/database/migrations/2026_10_28_083500_sync_security_guards_to_employees_table.php +++ b/database/migrations/2026_10_28_083500_sync_security_guards_to_employees_table.php @@ -1,8 +1,7 @@ get(); + $guardUsers = DB::table('users')->where('role', 'gate_officer')->get(); foreach ($guardUsers as $user) { - $emp = Employee::where('user_id', $user->id)->orWhere('nik', $user->username)->first(); + $emp = DB::table('employees') + ->where('user_id', $user->id) + ->orWhere('nik', $user->username) + ->first(); + if ($emp) { - $emp->update([ + DB::table('employees')->where('id', $emp->id)->update([ 'user_id' => $user->id, 'name' => $user->name, 'unit_kerja' => $emp->unit_kerja ?: 'Private Guard', 'division' => ($emp->division && $emp->division !== '-') ? $emp->division : 'Private Guard', 'position' => ($emp->position && $emp->position !== '-') ? $emp->position : 'Anggota', 'employee_type' => $emp->employee_type ?: 'Karyawan', + 'updated_at' => now(), ]); } else { - Employee::create([ + DB::table('employees')->insert([ 'user_id' => $user->id, 'nik' => $user->username, 'name' => $user->name, - 'photo_path' => $user->photo_path, + 'photo_path' => $user->photo_path ?? null, 'employee_type' => 'Karyawan', 'unit_kerja' => 'Private Guard', 'division' => 'Private Guard', 'position' => 'Anggota', 'is_operator' => false, + 'created_at' => now(), + 'updated_at' => now(), ]); } }