diff --git a/src/ArrayBuilder.php b/src/ArrayBuilder.php index fb67ce3..012e41d 100644 --- a/src/ArrayBuilder.php +++ b/src/ArrayBuilder.php @@ -205,11 +205,22 @@ protected function buildOrderBySingle($queryBuilder, $order) $order = strtolower($order); $orderBy = str_replace([' asc', ' desc'], '', $order); - $orderDirection = ends_with($order, ' desc') ? 'desc' : 'asc'; + $orderDirection = $this->ends_with($order, ' desc') ? 'desc' : 'asc'; $queryBuilder->orderBy($orderBy, $orderDirection); } + protected function ends_with($haystack, $needles) + { + foreach ((array) $needles as $needle) { + if (substr($haystack, -strlen($needle)) === (string) $needle) { + return true; + } + } + + return false; + } + /** * @param Builder|QueryBuilder $queryBuilder * @param int $limit