Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from Punksolid/newUserFactory
Updated user factory in default directory
- Loading branch information
Showing
1 changed file
with
28 additions
and
20 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,33 @@ | ||
<?php | ||
|
||
use Faker\Generator as Faker; | ||
namespace Database\Factories; | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Model Factories | ||
|-------------------------------------------------------------------------- | ||
| | ||
| This directory should contain each of the model factory definitions for | ||
| your application. Factories provide a convenient way to generate new | ||
| model instances for testing / seeding your application's database. | ||
| | ||
*/ | ||
use App\User; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
$factory->define(App\User::class, function (Faker $faker) { | ||
static $password; | ||
class UserFactory extends Factory | ||
{ | ||
/** | ||
* The name of the factory's corresponding model. | ||
* | ||
* @var string | ||
*/ | ||
protected $model = User::class; | ||
|
||
return [ | ||
'name' => $faker->name, | ||
'email' => $faker->unique()->safeEmail, | ||
'password' => $password ?: $password = bcrypt('secret'), | ||
'remember_token' => str_random(10), | ||
]; | ||
}); | ||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array | ||
*/ | ||
public function definition(): array | ||
{ | ||
static $password; | ||
|
||
return [ | ||
'name' => $this->faker->name, | ||
'email' => $this->faker->unique()->safeEmail, | ||
'password' => $password ?: $password = bcrypt('secret'), | ||
'remember_token' => str_random(10), | ||
]; | ||
} | ||
} |