tattran22 / response
There is no license information available for the latest version (2.0.4) of this package.
Easy API Response Transformation for Laravel
2.0.4
2024-03-28 08:14 UTC
Requires
- php: ^8.0
- laravel/framework: >=8.0
- spatie/laravel-fractal: ^6.0.3
README
This Laravel package simplifies handling API responses using the Fractal library. It lets you easily:
- Transform data: Convert raw data into structured responses.
- Include relationships: Add related data to your responses without separate requests.
- Handle pagination: Automatically add pagination links and metadata.
Installation
Just run this command in your terminal:
composer require tattran22/response
Usage
- Prepare your data: Use Eloquent models, arrays, or any suitable format.
- Create a transformer: Define how to transform your data using a
ResponseTransformer
class. - Transform your data: Call
transformData
with your data and transformer.use TatTran\Response\Transformers\ResponseTransformer; $transformer = new ResponseTransformer($manager); $response = $transformer->transformData($data, $transformerInstance);
- (Optional) Include relationships: Add
include
parameters to your API requests (e.g.,?include=relationship
).$transformer->setIncludes(['include1', 'include2']);
Features
- Easy transformation: Define transformations in clear, readable code.
- Includes parsing: Automatically handle
include
query parameters. - Pagination support: Add pagination links and metadata seamlessly.
- Set includes programmatically: Control included relationships in code.
Open Source & Credits
This package is free to use under the MIT license and developed by Tat Tran.