1. Go to this page and download the library: Download kent013/faker-json 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/ */
// same as {"faker_json":true,"method":"numberBetween","parameters":{"min":20,"max":30}}
$json = FakerFormatter::instance()
->method('numberBetween')
->addParameter('min', 20)
->addParameter('max', 30)->toJson();
$fakerFormatter = FakerFormatter::fromJson($json);
$result = FakerJson::call($fakerFormatter);
// result is number between 20 and 30
declare(strict_types=1);
namespace App\Providers;
use Faker\Provider\PHPFakerUtil;
use FakerJson\FakerJson;
use Illuminate\Support\ServiceProvider;
class FakerJsonServiceProvider extends ServiceProvider
{
/**
* Register services.
*/
public function register(): void
{
}
/**
* Bootstrap services.
*/
public function boot(): void
{
FakerJson::addProvider(PHPFakerUtil::class);
}
}