feat: add visibility check for leave requests based on user roles
This commit is contained in:
parent
c11962cda1
commit
a10a1700b0
@ -12,10 +12,16 @@
|
||||
|
||||
class LeaveRequestService
|
||||
{
|
||||
private function canViewAll(): bool
|
||||
{
|
||||
return auth()->user()->hasAnyRole(['developer', 'owner', 'direktur', 'admin-toko']);
|
||||
}
|
||||
|
||||
public function getAll(array $filters = []): Collection
|
||||
{
|
||||
return LeaveRequest::select(['id', 'employee_id', 'start_date', 'end_date', 'total_days', 'status', 'created_at'])
|
||||
->with(['employee.user.userProfile'])
|
||||
->when(! $this->canViewAll(), fn ($q) => $q->whereHas('employee', fn ($eq) => $eq->where('user_id', auth()->id())))
|
||||
->when($filters['status'] ?? null, function ($query, $status) {
|
||||
$query->where('status', $status);
|
||||
})
|
||||
@ -28,6 +34,7 @@ public function paginated(int $perPage = 25, string $search = '', string $sort =
|
||||
return LeaveRequest::query()
|
||||
->select(['id', 'employee_id', 'start_date', 'end_date', 'total_days', 'status', 'created_at'])
|
||||
->with(['employee.user.userProfile'])
|
||||
->when(! $this->canViewAll(), fn ($q) => $q->whereHas('employee', fn ($eq) => $eq->where('user_id', auth()->id())))
|
||||
->when($search, fn ($q) => $q->whereHas('employee.user.userProfile', fn ($uq) => $uq->where('full_name', 'like', "%{$search}%")))
|
||||
->when($filters['status'] ?? null, function ($query, $status) {
|
||||
$query->where('status', $status);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user