UserFactory.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. public function warehouseHead(): static
  51. {
  52. return $this->state(fn (array $attributes) => [
  53. 'role' => 'warehouse_head',
  54. ]);
  55. }
  56. public function assistantHead(): static
  57. {
  58. return $this->state(fn (array $attributes) => [
  59. 'role' => 'assistant_head',
  60. ]);
  61. }
  62. /**
  63. * Indicate that the model's email address should be unverified.
  64. */
  65. public function unverified(): static
  66. {
  67. return $this->state(fn (array $attributes) => [
  68. 'email_verified_at' => null,
  69. ]);
  70. }
  71. }