Download the PHP package mahmoud-birdsol/api-responses without Composer
On this page you can find all versions of the php package mahmoud-birdsol/api-responses. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mahmoud-birdsol/api-responses
More information about mahmoud-birdsol/api-responses
Files in mahmoud-birdsol/api-responses
Package api-responses
Short Description A responsable set of classes for resource api request
License MIT
Informations about the package api-responses
Api Responses
This package is a response helper classes for laravel api developers to use with transformers the package we use for transformers is spatie/laravel-fractal you will find some helper classes in this package for all rest api end points but the try value is in the Index response.
- Index Response
-
Show Response
- Updated Response
- Deleted Response
- Created Response
Installation
Config Paginator adapter can be configured, as well as the paginate request key.
Usage
Index Response
To return an index response from your controller you can just return a new instance of the class and pass through an eloquent model query builder and transformer. It's specifically designed that way so you can add any default queries you need to run on the model for example an authorization restriction scope that needs to exist on the model query level or a multi-tenant application in the same db you would filter the class from the backend.
Front end usage You can use request params to manipulate this response through some ready made functions.
- Pagination you can send a paginate=10 to get a paginated response from the api.
- Filters you can use eloquent scopes to filter for example filter by user id and you have a scope method on your model
public function scopeUser($query, $userId)
you can easily use this from your frontend by sending a request withuser={id}
. - Sorting You can sort response data also from your frontend by just passing through
latest=true
orsortAsc=email
orsortDesc=id
and just sort using any attribute you would like to use.
Show Response
A show response is just a simple class that will transform your data using fractal and return it to the user.
Updated Response
The updated response is very similar to the show response except that will refresh the updated model behind the scene so you can do something like this in your controller method easily.
License
The MIT License (MIT). Please see License File for more information.
All versions of api-responses with dependencies
laravel/framework Version ~5.5.0|~5.6.0|~5.7.0|~5.8.0|~6.0.0|~7.1|~8
spatie/laravel-fractal Version ^5.4