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] 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')) }}">
- - - + +
+
+ +