PHP code example of skovachev / fakefactory

1. Go to this page and download the library: Download skovachev/fakefactory 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/ */

    

skovachev / fakefactory example snippets


'providers' => array(
    'Skovachev\Fakefactory\FakefactoryServiceProvider',
)

'aliases' => array(
    'Fakefactory' => 'Skovachev\Fakefactory\Facade',
)

$user = Fakefactory::make('User');

$user = Fakefactory::create('User');

$user = Fakefactory::generateId()->create('User');

$user = Fakefactory::generateId(false)->create('User');

$user = Fakefactory::overrideAttributes(['username' => 'foobar'])->make('User');

$user = Fakefactory::make('User', ['username' => 'foobar']);

$user = Fakefactory::with('posts')->make('User');

$user = Fakefactory::with('posts')->make('User', [
	'username' => 'foobar',
	'posts' => [
		'title' => 'Fake title'
	]
]);

$user = Fakefactory::excludeAttributes('username')->make('User');


class UserFaker extends \Skovachev\Fakefactory\Faker
{
    protected $attributes = [
        'type' => ['randomElement', ['admin', 'client']]
    ];

    protected $relatedTo = ['posts'];
}

class UserFaker extends \Skovachev\Factory\Faker
{
    protected $with = ['account'];
}

Fakefactory::registerClassFaker('User', 'UserFaker');

$value = $faker->randomNumber(1, 10000);


class UserFaker extends \Skovachev\Fakefactory\Faker
{
    protected $attributes = [
        'username' => 'custom'
    ];

    public function getUsernameFakeValue($faker)
    {
        return $faker->randomNumber(1,1000) . '_' . $faker->lexify;
    }
}

protected $attributes = [
    'text' => 'paragraphs|3'
];

php artisan config:publish skovachev/fakefactory