PHP code example of vgirol / jsonapi-faker

1. Go to this page and download the library: Download vgirol/jsonapi-faker library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vgirol / jsonapi-faker example snippets


use VGirol\JsonApiFaker\Generator as JsonApiFaker;

$faker = new JsonApiFaker;

$factory = $faker->resourceObject();

$factory->setResourceType('test')
        ->setId('1')
        ->setAttributes([
            'attr1' => 'value1',
            'attr2' => 'value2'
        ])
        ->setMeta([
            'key1' => 'meta1'
        ])
        ->addLink('self', 'url');

$factory->fake();

$array = $factory->toArray();
$json = $factory->toJson();

use VGirol\JsonApiFaker\Generator as JsonApiFaker;

$json = new JsonApiFaker()
    ->resourceObject()
    ->fake()
    ->toJson();