fix(migration): use DB query builder instead of User model in sync_security_guards to avoid missing deleted_at column
This commit is contained in:
@@ -1,8 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Models\Employee;
|
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration
|
||||||
{
|
{
|
||||||
@@ -11,29 +10,36 @@ return new class extends Migration
|
|||||||
*/
|
*/
|
||||||
public function up(): void
|
public function up(): void
|
||||||
{
|
{
|
||||||
$guardUsers = User::where('role', 'gate_officer')->get();
|
$guardUsers = DB::table('users')->where('role', 'gate_officer')->get();
|
||||||
foreach ($guardUsers as $user) {
|
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) {
|
if ($emp) {
|
||||||
$emp->update([
|
DB::table('employees')->where('id', $emp->id)->update([
|
||||||
'user_id' => $user->id,
|
'user_id' => $user->id,
|
||||||
'name' => $user->name,
|
'name' => $user->name,
|
||||||
'unit_kerja' => $emp->unit_kerja ?: 'Private Guard',
|
'unit_kerja' => $emp->unit_kerja ?: 'Private Guard',
|
||||||
'division' => ($emp->division && $emp->division !== '-') ? $emp->division : 'Private Guard',
|
'division' => ($emp->division && $emp->division !== '-') ? $emp->division : 'Private Guard',
|
||||||
'position' => ($emp->position && $emp->position !== '-') ? $emp->position : 'Anggota',
|
'position' => ($emp->position && $emp->position !== '-') ? $emp->position : 'Anggota',
|
||||||
'employee_type' => $emp->employee_type ?: 'Karyawan',
|
'employee_type' => $emp->employee_type ?: 'Karyawan',
|
||||||
|
'updated_at' => now(),
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
Employee::create([
|
DB::table('employees')->insert([
|
||||||
'user_id' => $user->id,
|
'user_id' => $user->id,
|
||||||
'nik' => $user->username,
|
'nik' => $user->username,
|
||||||
'name' => $user->name,
|
'name' => $user->name,
|
||||||
'photo_path' => $user->photo_path,
|
'photo_path' => $user->photo_path ?? null,
|
||||||
'employee_type' => 'Karyawan',
|
'employee_type' => 'Karyawan',
|
||||||
'unit_kerja' => 'Private Guard',
|
'unit_kerja' => 'Private Guard',
|
||||||
'division' => 'Private Guard',
|
'division' => 'Private Guard',
|
||||||
'position' => 'Anggota',
|
'position' => 'Anggota',
|
||||||
'is_operator' => false,
|
'is_operator' => false,
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user