feat: Data Wali Murid terpisah — halaman khusus (daftar akun + anak + reset password), user internal difilter dari role parent

This commit is contained in:
Novy San87
2026-08-06 21:44:52 +07:00
parent c1cdc016ba
commit eb6d8c4256
5 changed files with 214 additions and 1 deletions
@@ -16,7 +16,7 @@ class UserController extends Controller
{
public function index(Request $request): View
{
$query = User::query();
$query = User::query()->where('role', '!=', 'parent'); // wali murid punya halaman sendiri
if ($request->filled('search')) {
$search = $request->search;
@@ -0,0 +1,39 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\View\View;
class WaliMuridController extends Controller
{
/**
* Data akun wali murid (terpisah dari user internal sekolah).
*/
public function index(Request $request): View
{
$query = User::query()
->where('role', 'parent')
->with(['parentStudents' => fn ($q) => $q->with('student:id,nisn,full_name,class_name')]);
if ($request->filled('search')) {
$search = $request->search;
$query->where(function ($q) use ($search) {
$q->where('name', 'like', "%{$search}%")
->orWhere('username', 'like', "%{$search}%")
->orWhere('phone', 'like', "%{$search}%");
});
}
$users = $query->orderByDesc('created_at')->paginate(20);
$total = User::where('role', 'parent')->count();
$totalAktif = User::where('role', 'parent')
->whereHas('parentStudents', fn ($q) => $q->where('status', 'active'))
->count();
return view('parents.index', compact('users', 'total', 'totalAktif'));
}
}