model ->select($select) ->with($relationships); if (!empty($data['customer_id'])) { $query->where('customer_id', $data['customer_id']); } if (!empty($data['status'])) { $query->where('status', $data['status']); } if (!empty($withCount)) { $query->withCount($withCount); } if ($returnQuery) { return $query; } if (!empty($data['paginate'])) { return $query->paginate( $data['per_page'] ?? 15 ); } return $query->get(); } }