UserFactory.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. 'username' => fake()->unique()->userName(),
  29. 'company_id' => 1,
  30. ];
  31. }
  32. /**
  33. * Indicate that the model's email address should be unverified.
  34. */
  35. public function unverified(): static
  36. {
  37. return $this->state(fn (array $attributes) => [
  38. 'email_verified_at' => null,
  39. ]);
  40. }
  41. }