Skip to content

Commit

Permalink
Use new factories
Browse files Browse the repository at this point in the history
Use the new factories provided in 8.x
  • Loading branch information
taylorotwell committed Apr 21, 2020
1 parent 0e01834 commit b9af2b2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
3 changes: 2 additions & 1 deletion app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
},
"autoload": {
"psr-4": {
"App\\": "app/"
"App\\": "app/",
"Database\\Factories\\": "database/factories/"
},
"classmap": [
"database/seeds",
Expand Down
43 changes: 20 additions & 23 deletions database/factories/UserFactory.php
Original file line number Diff line number Diff line change
@@ -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) {
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),
];
}
}

0 comments on commit b9af2b2

Please sign in to comment.