From 4790f85c23652ca5f9c199ef6e30bbe0b3874700 Mon Sep 17 00:00:00 2001 From: Edson Alves Date: Tue, 18 Aug 2020 16:57:59 -0300 Subject: [PATCH] add function ends_with (#26) --- src/ArrayBuilder.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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