Skip to content

Add Builder orders to Cachable Key #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 12, 2017
11 changes: 11 additions & 0 deletions src/CachedBuilder.php
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@ protected function getCacheKey(array $columns = ['*'], $idColumn = null) : strin
$key .= $this->getQueryColumns($columns);
$key .= $this->getWhereClauses();
$key .= $this->getWithModels();
$key .= $this->getOrderClauses();
$key .= $this->getOffsetClause();
$key .= $this->getLimitClause();

@@ -117,6 +118,16 @@ protected function getWithModels() : string
return '-' . implode('-', $eagerLoads->keys()->toArray());
}

protected function getOrderClauses(){
$orders = collect($this->query->orders);

return $orders->reduce(function($carry, $order){
$carry .= '_sort_' . array_get($order, 'column') . '_' . array_get($order, 'direction');

return $carry;
});
}

protected function getCacheTags() : array
{
return collect($this->eagerLoad)->keys()