From b9af2b229455efd68c806ff0f8f3d7e1411c9bbf Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 21 Apr 2020 10:12:39 -0500 Subject: [PATCH] Use new factories Use the new factories provided in 8.x --- app/User.php | 3 ++- composer.json | 3 ++- database/factories/UserFactory.php | 43 ++++++++++++++---------------- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/app/User.php b/app/User.php index e79dab7f..753cd717 100644 --- a/app/User.php +++ b/app/User.php @@ -3,12 +3,13 @@ namespace App; use Illuminate\Contracts\Auth\MustVerifyEmail; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; class User extends Authenticatable { - use Notifiable; + use HasFactory, Notifiable; /** * The attributes that are mass assignable. diff --git a/composer.json b/composer.json index 77300a49..e1406714 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,8 @@ }, "autoload": { "psr-4": { - "App\\": "app/" + "App\\": "app/", + "Database\\Factories\\": "database/factories/" }, "classmap": [ "database/seeds", diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 741edead..0e28020b 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -1,28 +1,25 @@ define(User::class, function (Faker $faker) { - return [ - 'name' => $faker->name, - 'email' => $faker->unique()->safeEmail, - 'email_verified_at' => now(), - 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password - 'remember_token' => Str::random(10), - ]; -}); +class UserFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return static + */ + public function definition() + { + return [ + 'name' => $this->faker->name, + 'email' => $this->faker->unique()->safeEmail, + 'email_verified_at' => now(), + 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password + 'remember_token' => Str::random(10), + ]; + } +}