model; if (count($relationships) > 0) { $model = $model->with($relationships); } $model = $model->select($select); if (isset($data['start']) && ! empty($data['start'])) { $model = $model->whereDate("start", ">=", $data['start']); } if (isset($data['end'])) { $model = $model->where(function ($query) use ($data) { if (isset($data['end']['condition'])) { switch (strtoupper($data['end']['condition'])) { case "IN": $query->whereIn($data['end']['key'], $data['end']['value']); break; case "NotIn": $query->whereNotIn($data['end']['key'], $data['end']['value']); break; default: $query->where($data['end']['key'], $data['end']['condition'], $data['end']['value']); break; } } else { $query->where($data['end']['key'], $data['end']['value']); } }); } if (isset($data['type']) && ! empty($data['type'])) { $model = $model->where("type", $data['phone']); } if (isset($data['status']) && ! empty($data['status']) && $data['status'] != 'full') { $model = $model->where("status", match ($data['status']) { 'active' => 1, 'de_active' => 0, 'closed' => 2, }); } if (count($withCount) > 0) { $model = $model->withCount($withCount); } if (isset($data['page'])) { return $model->paginate(15); } return $model->get(); } public function findBy(string $key, string $value) { if (empty($value) || empty($key)) { return false; } return $this->model->where($key, $value)->first(); } }