UserFactory.php 1004 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. protected static ?string $password;
  12. /**
  13. * Define the model's default state.
  14. *
  15. * @return array<string, mixed>
  16. */
  17. public function definition(): array
  18. {
  19. return [
  20. 'name' => fake()->name(),
  21. 'email' => fake()->unique()->safeEmail(),
  22. 'email_verified_at' => now(),
  23. 'password' => static::$password ??= Hash::make('password'),
  24. 'remember_token' => Str::random(10),
  25. ];
  26. }
  27. /**
  28. * Indicate that the model's email address should be unverified.
  29. */
  30. public function unverified(): static
  31. {
  32. return $this->state(fn (array $attributes) => [
  33. 'email_verified_at' => null,
  34. ]);
  35. }
  36. }