Skip to content
This repository has been archived by the owner on Nov 19, 2020. It is now read-only.

Commit

Permalink
adding email checker when calling seed factory
Browse files Browse the repository at this point in the history
  • Loading branch information
daison12006013 committed Feb 27, 2016
1 parent 1780588 commit 07686d0
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions database/factories/FakeUsers.php
@@ -1,11 +1,34 @@
<?php

$factory->define(Components\Model\User::class, function (Faker\Generator $faker) {
use Components\Model\User;

$factory->define(User::class, function (Faker\Generator $faker) {

$email_exists = true;

do {

$email = $faker->email;

$user = User::query()
->where('email = :email:')
->bind([
'email' => $email,
])
->execute();

if ( $user->getFirst() === false ) {
$email_exists = false;
}

} while($email_exists);

return [
'email' => $faker->email,
'email' => $email,
'name' => $faker->name,
'token' => str_random(100),
'is_activated' => (int) true,
'password' => password_hash(str_random(10), PASSWORD_BCRYPT),
];

});

0 comments on commit 07686d0

Please sign in to comment.