You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UserFactory.php 1.8KB

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