adrema/database/factories/UserFactory.php

42 lines
930 B
PHP
Raw Normal View History

2021-11-23 19:15:39 +01:00
<?php
namespace Database\Factories;
use App\User;
use Illuminate\Database\Eloquent\Factories\Factory;
2022-02-19 15:18:24 +01:00
use Illuminate\Support\Facades\Hash;
2021-11-23 19:15:39 +01:00
/**
* @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 [
2022-02-19 15:18:24 +01:00
'email' => $this->faker->safeEmail,
'password' => Hash::make('password'),
2024-07-31 22:41:02 +02:00
'firstname' => $this->faker->firstName,
'lastname' => $this->faker->lastName,
2021-11-23 19:15:39 +01:00
];
}
2024-08-02 15:12:47 +02:00
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]);
}
2021-11-23 19:15:39 +01:00
}