diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index 29178b7..1743448 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -78,7 +78,7 @@ protected function prepare() $constantParameters = $this->uriParser->constantParameters(); - array_map([$this, 'prepareConstants'], $constantParameters); + array_map([$this, 'prepareConstant'], $constantParameters); if ($this->hasIncludes() && $this->hasRelationColumns()) { $this->fixRelationColumns(); @@ -108,20 +108,20 @@ protected function build() return $this->query; } - private function prepareConstants($exceptKey) + private function prepareConstant($parameter) { - if (! $this->uriParser->hasQueryParameter($exceptKey)) return; + if (! $this->uriParser->hasQueryParameter($parameter)) return; - $callback = [$this, $this->setterMethodName($exceptKey)]; + $callback = [$this, $this->setterMethodName($parameter)]; - $callbackParameter = $this->uriParser->queryParameter($exceptKey); + $callbackParameter = $this->uriParser->queryParameter($parameter); call_user_func($callback, $callbackParameter['value']); } private function setIncludes($includes) { - $this->includes = explode(',', $includes); + $this->includes = array_filter(explode(',', $includes)); } private function setPage($page) @@ -149,9 +149,9 @@ private function setColumn($column) $this->columns[] = $column; } - private function appendRelationColumn($column) + private function appendRelationColumn($keyAndColumn) { - list($key, $column) = explode('.', $column); + list($key, $column) = explode('.', $keyAndColumn); $this->relationColumns[$key][] = $column; } @@ -202,7 +202,7 @@ private function appendOrderBy($order) private function setGroupBy($groups) { - $this->groupBy = explode(',', $groups); + $this->groupBy = array_filter(explode(',', $groups)); } private function setLimit($limit) @@ -223,14 +223,14 @@ private function addWhereToQuery($where) return $this->applyCustomFilter($key, $operator, $value); } - if (! $this->hasColumn($key)) { + if (! $this->hasTableColumn($key)) { throw new UnknownColumnException("Unknown column '{$key}'"); } $this->query->where($key, $operator, $value); } - private function addOrderByToQuery($order) + private function addOrderByToQuery(array $order) { extract($order); @@ -269,7 +269,7 @@ private function hasRelationColumns() return (count($this->relationColumns) > 0); } - private function hasColumn($column) + private function hasTableColumn($column) { return (Schema::hasColumn($this->model->getTable(), $column)); } diff --git a/src/UriParser.php b/src/UriParser.php index 67af212..9f4d288 100644 --- a/src/UriParser.php +++ b/src/UriParser.php @@ -38,21 +38,6 @@ public function __construct(Request $request) } } - public function pattern() - { - return $this->pattern; - } - - public function queryUri() - { - return $this->queryUri; - } - - public function queryParameters() - { - return $this->queryParameters; - } - public function queryParameter($key) { $keys = array_pluck($this->queryParameters, 'key');