feat: hapus akun wali murid — tombol Hapus + konfirmasi Swal, hapus user + tautan anak + perangkat (data siswa aman)
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ParentStudent;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
@@ -45,4 +46,19 @@ class WaliMuridController extends Controller
|
||||
|
||||
return view('parents.index', compact('users', 'total', 'totalAktif', 'pending', 'baruMingguIni'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Hapus akun wali murid beserta tautan anak & perangkatnya.
|
||||
* Hanya akun role=parent yang boleh dihapus lewat sini.
|
||||
*/
|
||||
public function destroy(int $userId): RedirectResponse
|
||||
{
|
||||
$user = User::where('role', 'parent')->findOrFail($userId);
|
||||
|
||||
$user->parentDevices()->delete();
|
||||
$user->parentStudents()->delete();
|
||||
$user->delete();
|
||||
|
||||
return back()->with('success', 'Akun wali "' . $user->name . '" beserta tautan & perangkatnya telah dihapus.');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user