Skip to content

Commit

Permalink
add function ends_with (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
edsonalvesan authored Aug 18, 2020
1 parent 00e2e86 commit 4790f85
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/ArrayBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4790f85

Please sign in to comment.