57 lines
1.3 KiB
PHP
57 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Support\Str;
|
|
|
|
/**
|
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
|
|
*/
|
|
class UserFactory extends Factory
|
|
{
|
|
/**
|
|
* The current password being used by the factory.
|
|
*/
|
|
protected static ?string $password = null;
|
|
|
|
/**
|
|
* Define the model's default state.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function definition(): array
|
|
{
|
|
return [
|
|
'name' => fake()->name(),
|
|
'email' => fake()->unique()->safeEmail(),
|
|
'password' => static::$password ??= Hash::make('password'),
|
|
'token' => bin2hex(random_bytes(32)),
|
|
'remember_token' => Str::random(10),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Indicate that the user is an admin.
|
|
*/
|
|
public function admin(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'name' => 'Admin User',
|
|
'email' => 'admin@example.com',
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Indicate that the user is a test user.
|
|
*/
|
|
public function test(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'name' => 'Test User',
|
|
'email' => 'test@example.com',
|
|
]);
|
|
}
|
|
}
|