PHP
laravel faker examples
//Usando Faker/Factory pra gerar valores fake
use FakerFactory as Faker;
$faker = Faker::create();
foreach(range(1, 30) as $index) {
Employee::create([
'email' => $faker->email(),
'name' => $faker->sentence(5),
'description' => $faker->paragraph(6),
]);
}
faker laravel
random_int(0, 12300)
Str::random(20)
$faker->word
$faker->sentence
$faker->paragraph
$faker->randomFloat(2, 0, 10000)
$faker->image('public/storage/images',640,480, null, false),
$faker->text(200)
$faker->numberBetween(10, 500)
$faker->unique()->numberBetween(100, 500)
$faker->userName,
$faker -> sentence(4,true),
<img src="/storage/images/{{$product->image}}">
string and number laravel faker
$this->faker->bothify('?###??##') // 1efr38qa
laravel faker example
php artisan make:factory PostFactory --model=Post
laravel faker
//For documentation, on tinker, run 'doc FakerFactory::create'
//Using Faker/Factory to generate fake values
$faker = FakerFactory::create();
$faker->email();
$faker->sentence(5);
$faker->paragraph(6);
laravel faker
$faker->text();
$faker->name();
$faker->sentence();
Laravel Faker
return [
...
'avatar' => $this->faker->imageUrl(40,40),
'status' => $this->faker->randomElement(['active','inactive','deleted']),
'country' => $this->faker->country,
];
laravel faker examples
(FakerFactory::create())->name();
laravel faker value or null
'parent_id' => $faker->boolean ? Page::all()->random()->id : null,
laravel faker example
php artisan make:factory PostFactory
laravel faker examples
//Usando Faker/Factory pra gerar valores fake
use FakerFactory as Faker;
$faker = Faker::create();
foreach(range(1, 30) as $index) {
Employee::create([
'email' => $faker->email(),
'name' => $faker->sentence(5),
'description' => $faker->paragraph(6),
]);
}
faker laravel
random_int(0, 12300)
Str::random(20)
$faker->word
$faker->sentence
$faker->paragraph
$faker->randomFloat(2, 0, 10000)
$faker->image('public/storage/images',640,480, null, false),
$faker->text(200)
$faker->numberBetween(10, 500)
$faker->unique()->numberBetween(100, 500)
$faker->userName,
$faker -> sentence(4,true),
<img src="/storage/images/{{$product->image}}">
string and number laravel faker
$this->faker->bothify('?###??##') // 1efr38qa
laravel faker example
php artisan make:factory PostFactory --model=Post
laravel faker
//For documentation, on tinker, run 'doc FakerFactory::create'
//Using Faker/Factory to generate fake values
$faker = FakerFactory::create();
$faker->email();
$faker->sentence(5);
$faker->paragraph(6);
laravel faker
$faker->text();
$faker->name();
$faker->sentence();
Laravel Faker
return [
...
'avatar' => $this->faker->imageUrl(40,40),
'status' => $this->faker->randomElement(['active','inactive','deleted']),
'country' => $this->faker->country,
];
laravel faker examples
(FakerFactory::create())->name();
laravel faker value or null
'parent_id' => $faker->boolean ? Page::all()->random()->id : null,
laravel faker example
php artisan make:factory PostFactory