php-tenant/Database/Factories/UserFactory.php

74 lines
1.8 KiB
PHP
Raw Permalink Normal View History

2026-01-26 21:08:59 +00:00
<?php
namespace Core\Tenant\Database\Factories;
2026-01-26 21:08:59 +00:00
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\Core\Tenant\Models\User>
2026-01-26 21:08:59 +00:00
*/
class UserFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* Uses the backward-compatible alias class to ensure type compatibility
* with existing code that expects Mod\Tenant\Models\User.
*/
protected $model = \Core\Tenant\Models\User::class;
2026-01-26 21:08:59 +00:00
/**
* The current password being used by the factory.
*/
protected static ?string $password;
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'name' => fake()->name(),
'email' => fake()->unique()->safeEmail(),
'email_verified_at' => now(),
'password' => static::$password ??= Hash::make('password'),
'remember_token' => Str::random(10),
'account_type' => 'apollo',
];
}
/**
* Create a Hades (admin) user.
*/
public function hades(): static
{
return $this->state(fn (array $attributes) => [
'account_type' => 'hades',
]);
}
/**
* Create an Apollo (standard) user.
*/
public function apollo(): static
{
return $this->state(fn (array $attributes) => [
'account_type' => 'apollo',
]);
}
/**
* Indicate that the model's email address should be unverified.
*/
public function unverified(): static
{
return $this->state(fn (array $attributes) => [
'email_verified_at' => null,
]);
}
}