diff --git a/composer.json b/composer.json index 5012689..d1aa0da 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Provides a Laravel API endpoint responder for the `react-dynamic-data-table` component.", "require": { "php": "^7.0.0", - "laravel/framework": "^5.1||^6.0", + "laravel/framework": "^5.1||^6.0||^7.0", "langleyfoxall/helpers-laravel": "^1.10" }, "autoload": { diff --git a/src/DataTableResponder.php b/src/DataTableResponder.php index 356360a..10f6067 100644 --- a/src/DataTableResponder.php +++ b/src/DataTableResponder.php @@ -1,11 +1,14 @@ model = new $className(); $this->request = $request; if (!$this->model instanceof Model) { - throw new \InvalidArgumentException('Provided class is not an Eloquent model.'); + throw new InvalidArgumentException('Provided class is not an Eloquent model.'); } } @@ -118,9 +121,9 @@ public function collectionManipulator(callable $collectionManipulator) /** * Sets the meta for the API response - * + * * @see DataTableResponder::makeMeta - * + * * @param callable $collectionManipulator * @return DataTableResponder */ @@ -134,13 +137,17 @@ public function setResponseMeta(array $meta = []) * Builds the Eloquent query based on the request. * * @param Request $request - * @return \Illuminate\Database\Eloquent\Builder + * @return Builder */ private function buildQuery(Request $request) { $orderByField = $request->get('orderByField'); $orderByDirection = $request->get('orderByDirection'); + if (!in_array(strtolower($orderByDirection), ['asc', 'desc'])) { + throw new InvalidArgumentException('Order by direction must be either asc or desc.'); + } + $query = $this->model->query(); if ($orderByField && $orderByDirection) { @@ -165,7 +172,7 @@ private function buildQuery(Request $request) /** * @param Builder $query - * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator + * @return LengthAwarePaginator */ private function paginateQuery(Builder $query) { @@ -173,8 +180,8 @@ private function paginateQuery(Builder $query) } /** - * @param \Illuminate\Contracts\Pagination\LengthAwarePaginator $results - * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator + * @param LengthAwarePaginator $results + * @return LengthAwarePaginator */ private function manipulateCollection($results) { @@ -257,7 +264,7 @@ private function disallowOrderingBy() } /** - * @return \Illuminate\Http\JsonResponse + * @return JsonResponse */ public function respond() {