Created
July 3, 2015 10:54
-
-
Save privatmamtora/08ceb187f910d24bb64e to your computer and use it in GitHub Desktop.
User Model Factory for seeding with Faker (created, updated, deleted timestamps)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$factory->define(\App\Models\User::class, function ($faker) { | |
$created = $faker->dateTimeBetween($startDate = '-30 years', $endDate = 'now'); | |
// Have 60% have updated records | |
$updated = $faker->optional($weight = 0.6)->dateTimeBetween($startDate = $created); | |
if(empty($updated)) { | |
// The rest 40% will have same date as created (unchanged record) | |
$updated = $created; | |
} | |
$deleted = $faker->optional($weight = 0.1)->dateTimeBetween($startDate = $updated); | |
return [ | |
'username' => $faker->name, | |
'email' => $faker->email, | |
'password' => str_random(10), | |
'created_at' => $created, | |
'updated_at' => $updated, | |
'deleted_at' => $deleted | |
]; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment