Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

UserFactory.php 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace Database\Factories;
  3. use App\Models\Company;
  4. use App\Models\Setting\CompanyDefault;
  5. use App\Models\Setting\CompanyProfile;
  6. use App\Models\User;
  7. use Illuminate\Database\Eloquent\Factories\Factory;
  8. use Illuminate\Support\Str;
  9. use Wallo\FilamentCompanies\Features;
  10. class UserFactory extends Factory
  11. {
  12. /**
  13. * The name of the factory's corresponding model.
  14. *
  15. * @var string
  16. */
  17. protected $model = User::class;
  18. /**
  19. * Define the model's default state.
  20. *
  21. * @return array<string, mixed>
  22. */
  23. public function definition(): array
  24. {
  25. return [
  26. 'name' => $this->faker->name(),
  27. 'email' => $this->faker->unique()->safeEmail(),
  28. 'email_verified_at' => now(),
  29. 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
  30. 'remember_token' => Str::random(10),
  31. 'profile_photo_path' => null,
  32. 'current_company_id' => null,
  33. ];
  34. }
  35. /**
  36. * Indicate that the model's email address should be unverified.
  37. */
  38. public function unverified(): static
  39. {
  40. return $this->state(function (array $attributes) {
  41. return [
  42. 'email_verified_at' => null,
  43. ];
  44. });
  45. }
  46. /**
  47. * Indicate that the user should have a personal company.
  48. */
  49. public function withPersonalCompany(): static
  50. {
  51. if (! Features::hasCompanyFeatures()) {
  52. return $this->state([]);
  53. }
  54. $countryCode = $this->faker->countryCode;
  55. return $this->afterCreating(function (User $user) use ($countryCode) {
  56. Company::factory()
  57. ->has(CompanyProfile::factory()->withCountry($countryCode), 'profile')
  58. ->afterCreating(function (Company $company) use ($user, $countryCode) {
  59. CompanyDefault::factory()->withDefault($user, $company, $countryCode)->create();
  60. })
  61. ->create([
  62. 'name' => $user->name . '\'s Company',
  63. 'user_id' => $user->id,
  64. 'personal_company' => true,
  65. ]);
  66. });
  67. }
  68. }