From d17dddf5fbcef8cc4e096774c5da237bf70f6eda Mon Sep 17 00:00:00 2001 From: 13Farahamalia <140934377+13Farahamalia@users.noreply.github.com> Date: Tue, 16 Jul 2024 10:33:56 +0700 Subject: [PATCH 1/3] backend update classroomStudent --- .../ClassroomStudentController.php | 23 +++++++++++++++++-- .../UpdateClassroomStudentRequest.php | 5 ++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/ClassroomStudentController.php b/app/Http/Controllers/ClassroomStudentController.php index e695f253..76985f77 100644 --- a/app/Http/Controllers/ClassroomStudentController.php +++ b/app/Http/Controllers/ClassroomStudentController.php @@ -68,9 +68,28 @@ public function edit(ClassroomStudent $classroomStudent) /** * Update the specified resource in storage. */ - public function update(UpdateClassroomStudentRequest $request, ClassroomStudent $classroomStudent) + public function update(UpdateClassroomStudentRequest $request, Classroom $classroom) { - // + // Convert comma-separated IDs to array + $addStudents = $request->input('add_students') ? explode(',', $request->input('add_students')) : []; + $removeStudents = $request->input('remove_students') ? explode(',', $request->input('remove_students')) : []; + + // Add students to classroom + foreach ($addStudents as $studentId) { + ClassroomStudent::firstOrCreate([ + 'classroom_id' => $classroom->id, + 'student_id' => $studentId, + ]); + } + + // Remove students from classroom + foreach ($removeStudents as $studentId) { + ClassroomStudent::where('classroom_id', $classroom->id) + ->where('student_id', $studentId) + ->delete(); + } + + return to_route('class.show', $classroom->id)->with('success', 'Berhasil meyimpan perubahan siswa'); } /** diff --git a/app/Http/Requests/UpdateClassroomStudentRequest.php b/app/Http/Requests/UpdateClassroomStudentRequest.php index b20445cf..9cc0380a 100644 --- a/app/Http/Requests/UpdateClassroomStudentRequest.php +++ b/app/Http/Requests/UpdateClassroomStudentRequest.php @@ -11,7 +11,7 @@ class UpdateClassroomStudentRequest extends FormRequest */ public function authorize(): bool { - return false; + return true; } /** @@ -22,7 +22,8 @@ public function authorize(): bool public function rules(): array { return [ - // + 'add_students' => 'nullable|string', + 'remove_students' => 'nullable|string', ]; } } From accd757e806aa5a71d76f10d4a0d84f6b7072480 Mon Sep 17 00:00:00 2001 From: 13Farahamalia <140934377+13Farahamalia@users.noreply.github.com> Date: Tue, 16 Jul 2024 10:34:18 +0700 Subject: [PATCH 2/3] fetch in-out student classroom --- .../school/pages/class/detail-class.blade.php | 96 ++++++++++++++----- routes/role/school.php | 2 + 2 files changed, 74 insertions(+), 24 deletions(-) diff --git a/resources/views/school/pages/class/detail-class.blade.php b/resources/views/school/pages/class/detail-class.blade.php index 437d8ee2..eba7cba6 100644 --- a/resources/views/school/pages/class/detail-class.blade.php +++ b/resources/views/school/pages/class/detail-class.blade.php @@ -23,46 +23,43 @@
- +
- +
- +
+ - @forelse ($students as $student) - + @foreach ($students as $student) + - @empty - - - - @endforelse + @endforeach
Siswa NISNAction
{{ $student->user->name }} {{ $student->nisn }}
- +
Semua siswa sudah memiliki kelas
-
@@ -71,39 +68,36 @@
- +
- +
+ - @forelse ($classroomStudents as $classroomStudent) - + @foreach ($classroomStudents as $classroomStudent) + - @empty - - - - @endforelse + @endforeach
Siswa NISNAction
{{ $classroomStudent->student->user->name }} {{ $classroomStudent->student->nisn }}
- +
Kelas ini kosong
-
@@ -112,6 +106,15 @@
+ +
+ @csrf + @method('PUT') + + +
+ +
@@ -137,7 +140,7 @@ @empty - + @endforelse @@ -164,3 +167,48 @@ @endsection +@section('script') + +@endsection \ No newline at end of file diff --git a/routes/role/school.php b/routes/role/school.php index 6fa5f885..3bdf5938 100644 --- a/routes/role/school.php +++ b/routes/role/school.php @@ -3,6 +3,7 @@ use App\Http\Controllers\AttendanceController; use App\Http\Controllers\AttendanceRuleController; use App\Http\Controllers\ClassroomController; +use App\Http\Controllers\ClassroomStudentController; use App\Http\Controllers\ExtracurricularController; use App\Http\Controllers\LessonHourController; use App\Http\Controllers\LevelClassController; @@ -153,3 +154,4 @@ Route::delete('school/delete-class/{classroom}', [ClassroomController::class, 'destroy'])->name('class.delete'); // detail kelas Route::get('school/{classroom}', [ClassroomController::class, 'show'])->name('class.show'); +Route::put('school/{classroom}', [ClassroomStudentController::class, 'update'])->name('classroom.update'); From c8d63236fb6dfca16c231d2a7f113eb9e79d3c58 Mon Sep 17 00:00:00 2001 From: jovitamaharani <141116867+jovitamaharani@users.noreply.github.com> Date: Tue, 16 Jul 2024 10:37:58 +0700 Subject: [PATCH 3/3] search dan filter pegawai --- app/Contracts/Interfaces/EmployeeInterface.php | 3 ++- .../Repositories/EmployeeRepository.php | 18 ++++++++++++++++-- .../Controllers/Teacher/StaffController.php | 5 +++-- .../views/school/pages/employe/index.blade.php | 11 +++++++---- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/app/Contracts/Interfaces/EmployeeInterface.php b/app/Contracts/Interfaces/EmployeeInterface.php index 610721c8..d0db4a5e 100644 --- a/app/Contracts/Interfaces/EmployeeInterface.php +++ b/app/Contracts/Interfaces/EmployeeInterface.php @@ -9,11 +9,12 @@ use App\Contracts\Interfaces\Eloquent\StoreInterface; use App\Contracts\Interfaces\Eloquent\UpdateInterface; use App\Contracts\Interfaces\Eloquent\WhereInterface; +use Illuminate\Http\Request; interface EmployeeInterface extends GetInterface, StoreInterface, UpdateInterface, ShowInterface, DeleteInterface, WhereInterface, ShowWithSlugInterface { public function paginate($query): mixed; - public function whereSchool(mixed $id, $query): mixed; + public function whereSchool(mixed $id, $query, Request $request): mixed; public function getTeacherBySchool(mixed $id): mixed; public function getCountEmployee(mixed $query) : mixed; public function getSchool(mixed $id): mixed; diff --git a/app/Contracts/Repositories/EmployeeRepository.php b/app/Contracts/Repositories/EmployeeRepository.php index cf645ec3..4e287826 100644 --- a/app/Contracts/Repositories/EmployeeRepository.php +++ b/app/Contracts/Repositories/EmployeeRepository.php @@ -5,6 +5,7 @@ use App\Contracts\Interfaces\EmployeeInterface; use App\Enums\RoleEnum; use App\Models\Employee; +use Illuminate\Http\Request; class EmployeeRepository extends BaseRepository implements EmployeeInterface { @@ -63,9 +64,22 @@ public function getTeacherBySchool(mixed $id): mixed return $this->model->query()->whereRelation('user.roles', 'name', RoleEnum::TEACHER->value)->where('school_id', $id)->get(); } - public function whereSchool(mixed $id, $query): mixed + public function whereSchool(mixed $id, $query, Request $request): mixed { - return $this->model->query()->whereRelation('user.roles', 'name', $query)->where('school_id', $id)->latest()->paginate(10); + return $this->model->query()->whereRelation('user.roles', 'name', $query) + ->where('school_id', $id) + ->when($request->search, function ($query) use ($request) { + $query->whereHas('user', function($q) use ($request){ + $q->where('name', 'LIKE', '%' . $request->search . '%'); + }); + })->when($request->filter === "terbaru", function($query) { + $query->latest(); + }) + ->when($request->filter === "terlama", function($query) { + $query->oldest(); + }) + ->latest() + ->paginate(10); } public function showWithSlug(string $slug): mixed diff --git a/app/Http/Controllers/Teacher/StaffController.php b/app/Http/Controllers/Teacher/StaffController.php index def02130..a2f742f9 100644 --- a/app/Http/Controllers/Teacher/StaffController.php +++ b/app/Http/Controllers/Teacher/StaffController.php @@ -12,6 +12,7 @@ use App\Http\Requests\UpdateEmployeeRequest; use App\Contracts\Interfaces\EmployeeInterface; use App\Contracts\Interfaces\ReligionInterface; +use Illuminate\Http\Request; class StaffController extends Controller { @@ -31,9 +32,9 @@ public function __construct(UserInterface $user, EmployeeInterface $employee, St /** * Display a listing of the resource. */ - public function index() + public function index(Request $request) { - $staffs = $this->employee->whereSchool(auth()->user()->school->id, RoleEnum::STAFF->value); + $staffs = $this->employee->whereSchool(auth()->user()->school->id, RoleEnum::STAFF->value, $request); $religions = $this->religion->get(); return view('school.pages.employe.index', compact('staffs', 'religions')); } diff --git a/resources/views/school/pages/employe/index.blade.php b/resources/views/school/pages/employe/index.blade.php index b4054006..97429ac7 100644 --- a/resources/views/school/pages/employe/index.blade.php +++ b/resources/views/school/pages/employe/index.blade.php @@ -18,18 +18,21 @@
+ placeholder="Cari" value="{{ old('search', request('search')) }}">
- - - + +
+
+ +
Kelas ini kosongKelas ini kosong