Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

UserFactory.php 1.8KB

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