UserFactory.php 1.0 KB

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