Laravel Populated Factory provides an easy way to generate factory data for models based on types and database column names.
Using the make:populated-factory
command by passing a model name and optional factory name override will create a new factory file based on the model. The command assumes the App
namespace, so you must pass the full namespace for models located elsewhere:
php artisan make:populated-factory User
The result is a populated factory file based on your model:
<?php
use Faker\Generator as Faker;
$factory->define(\App\User::class, function (Faker $faker) {
return [
'name' => $faker->name,
'email' => $faker->unique()->safeEmail,
'email_verified_at' => $faker->dateTime,
'password' => '$2y$10$uTDnsRa0h7wLppc8/vB9C.YqsrAZwhjCgLWjcmpbndTmyo1k5tbRC',
'remember_token' => $faker->sha1,
'created_at' => $faker->dateTime,
'updated_at' => $faker->dateTime,
];
});
You can learn more about this package, get full installation instructions, and view the source code on GitHub at coderello/laravel-populated-factory.
0 comments:
Post a Comment
Thanks