diff --git a/app/Services/Admin/Users/AdministratorService.php b/app/Services/Admin/Users/AdministratorService.php index 4945940..b7898ba 100644 --- a/app/Services/Admin/Users/AdministratorService.php +++ b/app/Services/Admin/Users/AdministratorService.php @@ -11,7 +11,11 @@ class AdministratorService { public function paginated(int $perPage = 25, string $search = '', ?string $gender = null): LengthAwarePaginator { - return User::with(['profile', 'roles']) + return User::select(['id', 'username', 'email', 'is_active']) + ->with([ + 'profile:id,user_id,full_name,phone_number,gender', + 'roles:id,name', + ]) ->whereHas('roles', fn ($q) => $q->whereIn('name', ['staff-admin', 'staff-keuangan'])) ->when($search, fn ($q) => $q->where(function ($query) use ($search) { $query->where('username', 'like', "%{$search}%") diff --git a/app/Services/Admin/Users/LecturerService.php b/app/Services/Admin/Users/LecturerService.php index e026147..d97f9d9 100644 --- a/app/Services/Admin/Users/LecturerService.php +++ b/app/Services/Admin/Users/LecturerService.php @@ -14,7 +14,12 @@ class LecturerService { public function getAllForSelect(): Collection { - return Lecturer::with('user.profile')->get(); + return Lecturer::select(['id', 'user_id', 'lecturer_number']) + ->with([ + 'user:id,username', + 'user.profile:id,user_id,full_name', + ]) + ->get(); } public function paginated(int $perPage = 25, string $search = '', ?string $gender = null, ?int $departmentId = null): LengthAwarePaginator @@ -33,7 +38,12 @@ public function forExport(string $search = '', ?string $gender = null, ?int $dep private function filteredQuery(string $search, ?string $gender, ?int $departmentId): Builder { - return User::with(['profile', 'lecturer.department']) + return User::select(['id', 'username', 'email', 'is_active']) + ->with([ + 'profile:id,user_id,full_name,phone_number,gender,birth_place,birth_date,address', + 'lecturer:id,user_id,lecturer_number,department_id', + 'lecturer.department:id,name', + ]) ->whereHas('roles', fn ($q) => $q->where('name', 'dosen')) ->when($search, fn ($q) => $q->where(function ($query) use ($search) { $query->where('username', 'like', "%{$search}%") diff --git a/app/Services/Admin/Users/StudentService.php b/app/Services/Admin/Users/StudentService.php index fa22701..fba3b62 100644 --- a/app/Services/Admin/Users/StudentService.php +++ b/app/Services/Admin/Users/StudentService.php @@ -14,7 +14,13 @@ class StudentService { public function getAllForSelect(): Collection { - return Student::with(['user.profile', 'department'])->get(); + return Student::select(['id', 'user_id', 'student_number', 'department_id']) + ->with([ + 'user:id,username', + 'user.profile:id,user_id,full_name', + 'department:id,name', + ]) + ->get(); } public function paginated(int $perPage = 25, string $search = '', ?string $gender = null, ?int $departmentId = null, ?string $status = null): LengthAwarePaginator @@ -33,7 +39,12 @@ public function forExport(string $search = '', ?string $gender = null, ?int $dep private function filteredQuery(string $search, ?string $gender, ?int $departmentId, ?string $status): Builder { - return User::with(['profile', 'student.department']) + return User::select(['id', 'username', 'email', 'is_active']) + ->with([ + 'profile:id,user_id,full_name,phone_number,gender,birth_place,birth_date,address', + 'student:id,user_id,student_number,department_id,enrollment_year,status', + 'student.department:id,name', + ]) ->whereHas('roles', fn ($q) => $q->where('name', 'mahasiswa')) ->when($search, fn ($q) => $q->where(function ($query) use ($search) { $query->where('username', 'like', "%{$search}%") diff --git a/database/seeders/UserSeeder.php b/database/seeders/UserSeeder.php index 6ac9969..6c87856 100644 --- a/database/seeders/UserSeeder.php +++ b/database/seeders/UserSeeder.php @@ -124,8 +124,8 @@ public function run(): void ], ], [ - 'username' => 'komoala', - 'email' => 'komoala@student.itmpwk.ac.id', + 'username' => 'komala', + 'email' => 'komala@student.itmpwk.ac.id', 'roles' => ['mahasiswa'], 'profile' => [ 'full_name' => 'Komala Dewi',