when($filters, function ($query) use ($filters) { if (isset($filters["employee_id"])) { $query->whereHas('employee', function (Builder $query) use ($filters) { $query->where('id', '=', $filters["employee_id"]); }); } if (isset($filters["status"])) { $query->where("status", $filters["status"]); } if (isset($filters["date"])) { $explodeDate = explode("to", $filters['date']); $query->whereBetween("start_date", [$explodeDate[0], preg_replace('/\s+/', '', $explodeDate[1])]); } })->get(); } public function getLeaveById($leaveId) { return Leave::findOrFail($leaveId); } public function delete($leaveId) { Leave::destroy($leaveId); } public function create(array $leaveDetails) { return Leave::create($leaveDetails); } public function update($leaveId, array $newDetails) { return Leave::where('leave_id', $leaveId)->update($newDetails); } }