vgirol / jsonapi-faker-laravel
This package provides a factory to generate fake data using Laravel and the JSON:API specification.
Requires
- php: ^7.3|^8.0
- laravel/framework: ^5.8|^6.0|^7.0|^8.0
- vgirol/jsonapi-faker: dev-master
Requires (Dev)
- fakerphp/faker: ^1.9.1
- infection/infection: ~0.14
- phpunit/phpunit: ^9.0
- vgirol/jsonapi-assert: dev-master
- vgirol/jsonapi-structure: dev-master
README
This package provides a set of factories to build fake data using Laravel and the JSON:API specification.
Technologies
- PHP 7.2+
- Laravel 5.8+
Installation
To install through composer, simply put the following in your composer.json
file:
{ "require-dev": { "vgirol/jsonapi-faker-laravel": "dev-master" } }
And then run composer install
from the terminal.
Quick Installation
Above installation can also be simplified by using the following command:
composer require vgirol/jsonapi-faker-laravel
Usage
First create a faker generator.
use VGirol\JsonApiFaker\Laravel\Generator as JsonApiFaker; $faker = new JsonApiFaker;
Then create a model and a factory.
$model = new DummyModel(); $factory = $faker->resourceObject($model, 'resourceType');
Next you can fill the factory ...
$factory->setMeta([ 'key1' => 'meta1' ]) ->addLink('self', 'url');
Finally export as an array or as JSON.
$array = $factory->toArray(); $json = $factory->toJson();
All these instructions can be chained.
use VGirol\JsonApiFaker\Generator as JsonApiFaker; $model = new DummyModel(); $json = new JsonApiFaker() ->resourceObject($model, 'resourceType') ->setMeta([ 'key1' => 'meta1' ]) ->toJson();
Documentation
The API documentation is available in XHTML format at the url http://jsonapi-faker-laravel.girol.fr/docs/ref/index.html.
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
composer test
Contributing
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please email vincent@girol.fr instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.