adrema/database/factories/UserFactory.php

42 lines
930 B
PHP

<?php
namespace Database\Factories;
use App\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
/**
* @extends Factory<User>
*/
class UserFactory extends Factory
{
protected $model = User::class;
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition()
{
return [
'email' => $this->faker->safeEmail,
'password' => Hash::make('password'),
'firstname' => $this->faker->firstName,
'lastname' => $this->faker->lastName,
];
}
public function name(string $name): self
{
[$firstname, $lastname] = explode(' ', $name);
return $this->state(['firstname' => $firstname, 'lastname' => $lastname]);
}
public function email(string $email): self
{
return $this->state(['email' => $email]);
}
}