Json Api Builder
This package is auto generate data follow jsonapi.org.
Install
Via Composer
$ composer require leeduc/json-api-builder
Once this has finished, you will need to add the service provider to the providers array in your app.php config as follows:
'providers' => [
// ...
Leeduc\JsonApiBuilder\JsonApiBuilderServiceProvider::class,
]
Next, also in the app.php config file, under the aliases array, you may want to add facades.
'aliases' => [
// ...
'JsonApiBuilder' => Leeduc\JsonApiBuilder\Facades\JsonApiBuilder::class,
]
Usage
Build Array
$builder = \JsonApiBuilder::setData($data)
->entity(['email', 'name', 'gender'], function($data) {
$data['id'] = 100;
return $data;
})
->relationship(['comments'])
->included(['comments' => ['post_id', 'content']]);
dd($builder->parse()); // Array data
Build Json
$builder = \JsonApiBuilder::setData($data)
->entity(['email', 'name', 'gender'], function($data) {
$data['id'] = 100;
return $data;
})
->relationship(['comments'])
->included(['comments' => ['post_id', 'content']])
->json()
->meta([
'version' => '1.0'
])
->pagination([
'next' => 'example/next',
'pre' => 'example/pre'
])
->response();
dd($builder); // Class Symfony\Component\HttpFoundation\Response
dd(builder->getContent()); // Get Json
Change log
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING and CONDUCT for details.
Security
If you discover any security related issues, please email lee.duc55@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.