fix: simpan nomor HP wali saat registrasi & taut anak → kolom HP terisi, backfill data siswa saat approve jalan, auto-verifikasi kini benar-benar berfungsi (diuji end-to-end +62 vs 0)

This commit is contained in:
Novy San87
2026-08-06 22:10:34 +07:00
parent 505d060df2
commit 5b66339951
3 changed files with 15 additions and 2 deletions
@@ -43,10 +43,11 @@ class ParentVerificationController extends Controller
]); ]);
// Isi data kontak wali ke siswa bila masih kosong // Isi data kontak wali ke siswa bila masih kosong
if ($link->student && empty($link->student->parent_phone)) { // (user->phone kini terisi sejak registrasi — register & link-child menyimpannya)
if ($link->student && empty($link->student->parent_phone) && ! empty($link->user->phone)) {
$link->student->update([ $link->student->update([
'parent_name' => $link->user->name, 'parent_name' => $link->user->name,
'parent_phone' => $link->user->phone ?: ($link->student->parent_phone), 'parent_phone' => $link->user->phone,
]); ]);
} }
@@ -77,9 +77,16 @@ class ParentAuthController extends Controller
'role' => 'parent', 'role' => 'parent',
'roles' => ['parent'], 'roles' => ['parent'],
'is_active' => true, 'is_active' => true,
'phone' => $phone,
]); ]);
} }
// Simpan nomor HP wali ke akun bila masih kosong (dipakai juga
// untuk mengisi data kontak siswa saat verifikasi oleh admin).
if (empty($user->phone)) {
$user->update(['phone' => $phone]);
}
// Verifikasi otomatis jika HP cocok dengan data orang tua di database // Verifikasi otomatis jika HP cocok dengan data orang tua di database
$autoVerified = PhoneHelper::matches($phone, $student->parent_phone); $autoVerified = PhoneHelper::matches($phone, $student->parent_phone);
@@ -531,6 +531,11 @@ class ParentStudentController extends Controller
$autoVerified = PhoneHelper::matches(trim($validated['parent_phone']), $student->parent_phone); $autoVerified = PhoneHelper::matches(trim($validated['parent_phone']), $student->parent_phone);
// Simpan nomor HP wali bila akun belum punya.
if (empty($user->phone)) {
$user->update(['phone' => trim($validated['parent_phone'])]);
}
$link = ParentStudent::create([ $link = ParentStudent::create([
'user_id' => $user->id, 'user_id' => $user->id,
'student_id' => $student->id, 'student_id' => $student->id,