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; namespace App;
use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable; use Illuminate\Notifications\Notifiable;
class User extends Authenticatable class User extends Authenticatable
{ {
use Notifiable; use HasFactory, Notifiable;
/** /**
* The attributes that are mass assignable. * The attributes that are mass assignable.

View File

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

View File

@ -1,28 +1,25 @@
<?php <?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */ namespace Database\Factories;
use App\User; use Illuminate\Database\Eloquent\Factories\Factory;
use Faker\Generator as Faker;
use Illuminate\Support\Str; use Illuminate\Support\Str;
/* class UserFactory extends Factory
|-------------------------------------------------------------------------- {
| Model Factories /**
|-------------------------------------------------------------------------- * Define the model's default state.
| *
| This directory should contain each of the model factory definitions for * @return static
| your application. Factories provide a convenient way to generate new */
| model instances for testing / seeding your application's database. public function definition()
| {
*/ return [
'name' => $this->faker->name,
$factory->define(User::class, function (Faker $faker) { 'email' => $this->faker->unique()->safeEmail,
return [ 'email_verified_at' => now(),
'name' => $faker->name, 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
'email' => $faker->unique()->safeEmail, 'remember_token' => Str::random(10),
'email_verified_at' => now(), ];
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password }
'remember_token' => Str::random(10), }
];
});