UserFactory.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace Database\Factories;
  3. use Illuminate\Database\Eloquent\Factories\Factory;
  4. use Illuminate\Support\Facades\Hash;
  5. use Illuminate\Support\Str;
  6. /**
  7. * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
  8. */
  9. class UserFactory extends Factory
  10. {
  11. /**
  12. * The current password being used by the factory.
  13. */
  14. protected static ?string $password;
  15. /**
  16. * Define the model's default state.
  17. *
  18. * @return array<string, mixed>
  19. */
  20. public function definition(): array
  21. {
  22. return [
  23. 'name' => fake()->name(),
  24. 'email' => fake()->unique()->safeEmail(),
  25. 'email_verified_at' => now(),
  26. 'password' => static::$password ??= Hash::make('password'),
  27. 'remember_token' => Str::random(10),
  28. 'role' => 'user',
  29. 'phone' => fake()->optional()->phoneNumber(),
  30. ];
  31. }
  32. public function admin(): static
  33. {
  34. return $this->state(fn (array $attributes) => [
  35. 'role' => 'admin',
  36. ]);
  37. }
  38. public function manager(): static
  39. {
  40. return $this->state(fn (array $attributes) => [
  41. 'role' => 'manager',
  42. ]);
  43. }
  44. public function brigadier(): static
  45. {
  46. return $this->state(fn (array $attributes) => [
  47. 'role' => 'brigadier',
  48. ]);
  49. }
  50. /**
  51. * Indicate that the model's email address should be unverified.
  52. */
  53. public function unverified(): static
  54. {
  55. return $this->state(fn (array $attributes) => [
  56. 'email_verified_at' => null,
  57. ]);
  58. }
  59. }