Use new factories

Use the new factories provided in 8.x
This commit is contained in:
Taylor Otwell 2020-04-21 10:12:39 -05:00
parent 0e01834bed
commit b9af2b2294
3 changed files with 24 additions and 25 deletions

View File

@ -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.

View File

@ -33,7 +33,8 @@
},
"autoload": {
"psr-4": {
"App\\": "app/"
"App\\": "app/",
"Database\\Factories\\": "database/factories/"
},
"classmap": [
"database/seeds",

View File

@ -1,28 +1,25 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
namespace Database\Factories;
use App\User;
use Faker\Generator as Faker;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
/*
|--------------------------------------------------------------------------
| 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.
|
*/
$factory->define(User::class, function (Faker $faker) {
class UserFactory extends Factory
{
/**
* Define the model's default state.
*
* @return static
*/
public function definition()
{
return [
'name' => $faker->name,
'email' => $faker->unique()->safeEmail,
'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),
];
});
}
}