[Feature]: Spatie Laravel-Query-Builder follow DTO via Spatie Laravel-data
Opened this issue · 2 comments
What happened?
Allow handlers to conform to DTO. (these also need to be created/generated...)
$query = static::getEloquentQuery();
$model = static::getModel();
$query = QueryBuilder::for($query)
->allowedFields($model::$allowedFields ?? [])
->allowedSorts($model::$allowedSorts ?? [])
->allowedFilters($model::$allowedFilters ?? [])
->allowedIncludes($model::$allowedIncludes ?? null)
->paginate(request()->query('per_page'))
->appends(request()->query())
;
instead of:
return static::getApiTransformer()::collection($query)
use this:
return static::getApiTransformer()::collection(BlogData::collect($query));
where BlogData is a spatie laravel-data DTO.
The benefit would be that because the DTO knows column types etc. this information can be used to generate correct API Swagger docs for Schemas, Parameters etc.. see:
https://github.com/xolvionl/laravel-data-openapi-generator/tree/main/src/Data
How to reproduce the bug
nice to have
Package Version
latest
PHP Version
8.3
Laravel Version
11
Which operating systems does with happen with?
No response
Notes
No response
i think this is good to have, we can use the DTO for request validation too.
i've created a simple version of the DTO implementation in this branch with PR: #57
But as i'm trying to get it to work i notice that it would be easier to generate the docs like xolvionl/laravel-data-openapi-generator does it....
It just directly generates a swagger json from the Routes(). so no annotations needed. When i have more time i think i will convert it like this as this would be easier to maintain instead of re-running the commands for generating a transformer or something...