All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
- Replaced package
open-southeners/laravel-helpers
withopen-southeners/extended-php
- Performance degradation issue on serialisation (infinite loop on nested includeds)
- Laravel 11 support
- Raw response without pagination returning query builder
- Raw response formatting to
JsonApiResponse
- Type generics into:
OpenSoutheners\LaravelApiable\Http\JsonApiResponse
OpenSoutheners\LaravelApiable\Http\RequestQueryObject
OpenSoutheners\LaravelApiable\Http\Resources\JsonApiResource
OpenSoutheners\LaravelApiable\Http\Resources\JsonApiCollection
OpenSoutheners\LaravelApiable\Contracts\ViewQueryable
OpenSoutheners\LaravelApiable\Contracts\ViewableBuilder
Handler::withHeader
(used asapiable()->jsonApiRenderable()->withHeader
) to add headers to JSON errors
- Includes relationships counts with
tags_count
(needs to end with_count
). E.g:
JsonApiResponse::using(Post::class)->allowInclude(['tags_count']);
// Then request this with ?include=tags_count
- Some IDEs getting confused with returning
self
types in traits (replaced tostatic
)
- Fix
open-southeners/laravel-helpers
utilities package version constrain so other packages can use similar versions under the same major release
- Query
withCount
method usage with apiable is replacing the underlying added selects for these counts
- Force formatting always coming through even thought is not forced by config
- Config file now with
response.formatting
withtype
andforce
sub-items as options
- Force formatting for Inertia based apps (now can use
Apiable::forceResponseFormatting()
)
- Non existing class
ForceAppendAttribute
when reading controller attributes
- Default sorts using
JsonApiResponse::applyDefaultSort
method orOpenSoutheners\LaravelApiable\Attributes\ApplyDefaultSort
attribute - Default filters using
JsonApiResponse::applyDefaultFilter
method orOpenSoutheners\LaravelApiable\Attributes\ApplyDefaultFilter
attribute - Default formatting bypass using
JsonApiResponse::forceFormatting
method
Request::wantsJsonApi()
only looks atAccept
header, not looking forContent-Type
one anymore- Now all requests can send a different
Accept
header if they want a diffent response formatting. For e.g. sendingAccept: application/json
will get raw JSON response. Default being configured in theconfig/apiable.php
make sure to publish or update it
- Sorts now accepts relationships (for e.g.
/posts?sort=tags.created_at
)
- PHP deprecation warning on string vars interpolation
JsonApiResponse
using viewable builder (query scopes to filter by view permission) didn't send any user as first parameter
JsonApiResponse::paginateUsing(fn ($query) => $query->simplePaginate())
method to customise pagination used in JSON API responses.
- Pivot attributes now aren't configurable through
config/apiable.php
, they will always be applied as long as there are any under the relationship. They can be found underrelationships.data.*.meta
and keyed following the same as before:pivot_name_pivot_attribute
(pivot_name
being customisable through: https://laravel.com/docs/10.x/eloquent-relationships#customizing-the-pivot-attribute-name)
- Missing import to make work pivot attributes functionality
include_pivot_attributes
config option to optionally add pivot attributes to the relationships data (default to false to match previous functionality). Pivot data will be added aspivot_name_pivot_attribute
(remember if you're usingas
it will use this one: https://laravel.com/docs/10.x/eloquent-relationships#customizing-the-pivot-attribute-name).
- Added status code (401) to unauthorised responses
- Inconsistent behaviour with
Apiable::toJsonApi()
returning false sometimes, now returns an API resource/collection all the time (might be a breakchange therefore this was minor release)
JsonApiResponse::conditionallyLoadResults()
method doesn't work as expected
- Exceptions handler using
apiable()->jsonApiRenderable()
now returns thrown exception headers
- Backend now returns properly the
Content-Type=application/vnd.api+json
response header
- Filters with negative values like
filter[attr]=0
won't be filtered out
Apiable::jsonApiRenderable
method, Handler missing import of Symfony's HttpException
Apiable::jsonApiRenderable
now accepts 2 arguments: Throwable exception & second a bool nullable withTrace, error handling redesign to properly match JSON:API & Laravel.
JsonApiResponse::conditionallyLoadResults
to manage adding viewable query or not to the response
- Laravel 10 support
- PHP native types
QueryParametersValidator
constantsENFORCE_VALIDATION_STRATEGY
&FILTER_VALIDS_ONLY_STRATEGY
, now strategy parameter is changed to a boolean instead
- Types with static analysis
- Error when wrong typed parameter sent to
IteratesResultsAfterQuery::appendToApiResource
- Filtering when wrong operator is present was returning exception, now ignores the operator (e.g.
filter[attribute][0]=1&filter[attribute][1]=2
)
- Deprecation notice on
explode
second argument
forceAppendWhen
method toJsonApiResponse
- Fix PHP 8 deprecation with string variable interpolation
- Fix issue reporting wrong status code when setup handler renderable receives a query exception:
apiable()->jsonApiRenderable()
- Filters values like:
filter[attribute]=0
now doesn't get removed
- PHP 8.2 deprecation warnings
- PHP 8.2 support
- Fixed OR filters with rest of filtering or SQL query affecting negatively the results
- Fixed
page[size]
in request doesn't get the number of results when lower than model's$perPage
(only on higher)
- Filtering scopes were not being applied
- Search (Laravel Scout) filters with allowed attributes and/or value(s):
?q=hello&q[filter][attribute]=foo
or?search=hello&search[filter][attribute]=foo
- Empty filter without attribute:
?filter=test
was throwing an error
- Remove page parameter from pagination links when using
withQuery
- Filter relationship without any value applies relationship existence filtering, now doesn't
- Filtering now handles AND/OR conditions properly
- Filtering using OR condition (
filter[status]=Active,Inactive
) will be fully invalidated if one member doesn't pass the validation RequestQueryObject::filters
method now implements own logic instead of reusing Symfony's request one to be able to get AND filters with same keys (attributes) on a different array item
withWhereHas
under filtering, now all related data is loaded (until reimplemented with AND/OR conditionals...)
- Fix issue reporting wrong status code when setup handler renderable receives a query exception:
apiable()->jsonApiRenderable()
- Add request query parameters to pagination links on
JsonApiResponse
resource collections
- Ambiguous columns when filtering on relationships attributes (redoing it right without any regression)
- Ambiguous columns when filtering on relationships attributes
- Conditionally filter out attributes that ends with "_id" (adding config option
responses.include_ids_on_attributes
) JsonApiResponse::includingIdAttributes()
method for settingresponses.include_ids_on_attributes
option value within an individual response
- Fix
resolveFromRoute
when using invokable controllerJsonApiResponse
JsonApiResponse::toArray
returning wrong formatted JSON:API array
JsonApiResponse::forceAppend
method fails getting model class when from query builder
requests.validate_params
config option toapiable.php
for enforcing validation. Requires to publish or manually copy [#7]- Additional filter operators like
gte
(greater or equal than),gt
(greater than),lte
(lower or equal than),lt
(lower than) [#5]
- Get allowed fields methods from apply query params pipeline classes moved to
OpenSoutheners\LaravelApiable\Http\QueryParamsValidator
- Operators from
allowed_filters
included to meta data are now URL-safe allowed_sorts
structure is now based on['attribute' => 'allowed_direction']
- Allow filters methods/attribute now accepts array with multiple operators
Illuminate\Contracts\Support\Arrayable
interface toJsonApiResponse
so it can be used in Inertia responses (as an example)
OpenSoutheners\LaravelApiable\Contracts\ViewQueryable
andOpenSoutheners\LaravelApiable\Contracts\ViewableBuilder
classes for models & custom query builders now functional withJsonApiResponse
(can be disabled by config seeconfig/apiable.php
)
php artisan vendor:publish --force --provider="OpenSoutheners\LaravelApiable\ServiceProvider"
- Getting wrong config keys
php artisan vendor:publish --force --provider="OpenSoutheners\LaravelApiable\ServiceProvider"
JsonApiResponse::list
andJsonApiResponse::getOne
methods as isn't the responsibility of this package to act as query repository so it makes easier to encapsulate it into repository or whatever design pattern you're using. UseJsonApiResponse::using
instead sending the query as its parameter.
- PHP 8 attributes for QueryParams:
OpenSoutheners\LaravelApiable\Attributes\FilterQueryParam
OpenSoutheners\LaravelApiable\Attributes\IncludeQueryParam
OpenSoutheners\LaravelApiable\Attributes\AppendsQueryParam
OpenSoutheners\LaravelApiable\Attributes\FieldsQueryParam
OpenSoutheners\LaravelApiable\Attributes\SortQueryParam
OpenSoutheners\LaravelApiable\Attributes\SearchQueryParam
- Method
JsonApiResponse::from
can now be non-statically called asJsonApiResponse::using
(for dependency injection usage in controllers, etc)
- Config file changes. Please make sure to run
php artisan vendor:publish --force --provider="OpenSoutheners\LaravelApiable\ServiceProvider"
- Constructor from
JsonApiResponse
now only accepts 1 optional parameter (being the query parameter removed in favor of manually setting this by callingJsonApiResponse::using
method) - Constructor from
RequestQueryObject
now only accepts 1 optional parameter (being the query parameter removed in favor of manually setting this by callingRequestQueryObject::setQuery
method)
JsonApiResponse:forceAppend
method to force appends to the final response
JsonApiResponse::getPipelineQuery
now accepts an optional callback closure & is exposed as public for repositories usage
RequestQueryObject::allowFilter
method now accepts 3 arguments (attribute, operator/values, values)
AllowedFilter::scopedValue
method was removed and accidentally pushed ontoRequestQueryObject::allowScopedFilter
- Method
RequestQueryObject::allows
to be able to group everything in the same method call without needing to use class methods (AllowedFilters
,AllowedFields
, etc...)
AllowedFilter::scoped
method for Laravel query scopes filters to specify the filter is not an actual attribute but a query builder scopeenforce_scoped_names
toconfig/apiable.php
to be used so they rename scoped filters in case there are attributes with the same name on the model (remember to usevendor:publish
artisan command to update the config file)include_allowed
toconfig/apiable.php
to be used so anyJsonApiResponse
will include allowed filters and sorts (like usingJsonApiResponse::includeAllowedToResponse
but on all requests)AssertableJsonApi::hasNotAttribute
andAssertableJsonApi::hasNotAttributes
methods for negative test assertions (counter part ofAssertableJsonApi::hasAttribute
andAssertableJsonApi::hasAttributes
)
- Scoped filters now can be allowed & applied to requested response
- Issue with
allowAppends
&allowFields
sending array of attributes will wrongly parse them
- Allowing fields and appends now accepts model class as for type parameter
- Missing publishable config
- Custom transformers (out of package scope / purpose)
- Method
allowIncludes
adds nested array which leads into issues
- Model setup not needed (
OpenSoutheners\LaravelApiable\JsonApiOptions
replaced byOpenSoutheners\LaravelApiable\Facades\Apiable::modelResourceTypeMap
facade method)
- Support for laravel/scout
- Support for hammerstone/fast-paginate
- Missing autoload-dev, tests were autoloaded with the released version
- Multiple minor fixes around forwarding calls (methods)
- Apiable facade
toJsonApi
- Way to add multiple sorts and includes with
allowSort
&allowInclude
methods
- JsonApiResponse
getOne
method for parse current model instance or model key passed isCollection
andisResource
testing methods toAssertableJsonApi
- Multiple fixes to tests & package
- Appends now needs to be sent as
?appends[type]=my_attribute,another_attribute
as they're completely different from fields
JsonApiResource::withRelations()
method (bad idea, lots of possible N+1 problems to the dev-user)
- Initial pre-release!