diff --git a/src/Contracts/HasAllowedIncludes.php b/src/Contracts/HasAllowedIncludes.php new file mode 100644 index 0000000..7072860 --- /dev/null +++ b/src/Contracts/HasAllowedIncludes.php @@ -0,0 +1,8 @@ +panel; diff --git a/stubs/PaginationHandler.stub b/stubs/PaginationHandler.stub index 62f36cc..62951db 100644 --- a/stubs/PaginationHandler.stub +++ b/stubs/PaginationHandler.stub @@ -17,10 +17,10 @@ class PaginationHandler extends Handlers { $model = static::getModel(); $query = QueryBuilder::for($query) - ->allowedFields($model::getAllowedFields() ?? []) - ->allowedSorts($model::getAllowedSorts() ?? []) - ->allowedFilters($model::getAllowedFilters() ?? []) - ->allowedIncludes($model::getAllowedIncludes() ?? []) + ->allowedFields($this->getAllowedFields() ?? []) + ->allowedSorts($this->getAllowedSorts() ?? []) + ->allowedFilters($this->getAllowedFilters() ?? []) + ->allowedIncludes($this->getAllowedIncludes() ?? []) ->paginate(request()->query('per_page')) ->appends(request()->query()); diff --git a/tests/Fixtures/Resources/ProductResource/Api/Handlers/PaginationHandler.php b/tests/Fixtures/Resources/ProductResource/Api/Handlers/PaginationHandler.php index 67861d8..d6cef72 100644 --- a/tests/Fixtures/Resources/ProductResource/Api/Handlers/PaginationHandler.php +++ b/tests/Fixtures/Resources/ProductResource/Api/Handlers/PaginationHandler.php @@ -15,28 +15,12 @@ public function handler() { $model = static::getModel(); - $allowedFields = method_exists($model, 'getAllowedFields') && is_array($model::getAllowedFields()) - ? $model::getAllowedFields() - : (property_exists($model, 'allowedFields') && is_array($model::$allowedFields) - ? $model::$allowedFields - : []); - - $allowedSorts = method_exists($model, 'getAllowedSorts') && is_array($model::getAllowedSorts()) - ? $model::getAllowedSorts() - : (property_exists($model, 'allowedSorts') && is_array($model::$allowedSorts) - ? $model::$allowedSorts - : []); - - $allowedFilters = method_exists($model, 'getAllowedFilters') && is_array($model::getAllowedFilters()) - ? $model::getAllowedFilters() - : (property_exists($model, 'allowedFilters') && is_array($model::$allowedFilters) - ? $model::$allowedFilters - : []); $query = QueryBuilder::for($model) - ->allowedFields($allowedFields) - ->allowedSorts($allowedSorts) - ->allowedFilters($allowedFilters) + ->allowedFields($this->getAllowedFields() ?? []) + ->allowedSorts($this->getAllowedSorts() ?? []) + ->allowedFilters($this->getAllowedFilters() ?? []) + ->allowedIncludes($this->getAllowedIncludes() ?? []) ->paginate(request()->query('per_page')) ->appends(request()->query());