Skip to content

Commit

Permalink
search dan filter pegawai
Browse files Browse the repository at this point in the history
  • Loading branch information
jovitamaharani committed Jul 16, 2024
1 parent 37aad98 commit c8d6323
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
3 changes: 2 additions & 1 deletion app/Contracts/Interfaces/EmployeeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 16 additions & 2 deletions app/Contracts/Repositories/EmployeeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions app/Http/Controllers/Teacher/StaffController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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'));
}
Expand Down
11 changes: 7 additions & 4 deletions resources/views/school/pages/employe/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,21 @@
<div class="position-relative">
<div class="">
<input type="text" name="search" class="form-control search-chat py-2 px-5 ps-5" id="search-name"
placeholder="Cari">
placeholder="Cari" value="{{ old('search', request('search')) }}">
<i class="ti ti-search position-absolute top-50 translate-middle-y fs-6 text-dark ms-3"></i>
</div>
</div>

<div class="d-flex gap-2">
<select name="" class="form-select" id="search-status">
<select name="filter" class="form-select" id="search-status">
<option value="">Tampilkan semua</option>
<option value="">Terbaru</option>
<option value="">Terlama</option>
<option value="terbaru">Terbaru</option>
<option value="terlama">Terlama</option>
</select>
</div>
<div>
<button type="submit" class="btn btn-primary btn-md">filter</button>
</div>
</form>
</div>
<div class="col-lg-6 mb-3">
Expand Down

0 comments on commit c8d6323

Please sign in to comment.