UserFactory.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace Database\Factories;
  3. use App\Models\Company;
  4. use Illuminate\Database\Eloquent\Factories\Factory;
  5. use Illuminate\Support\Facades\Hash;
  6. use Illuminate\Support\Str;
  7. /**
  8. * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\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. 'username' => fake()->unique()->userName(),
  30. 'company_id' => Company::factory()->create(),
  31. ];
  32. }
  33. /**
  34. * Indicate that the model's email address should be unverified.
  35. */
  36. public function unverified(): static
  37. {
  38. return $this->state(fn (array $attributes) => [
  39. 'email_verified_at' => null,
  40. ]);
  41. }
  42. }