AuditionAdminBilling/database/factories/ContactFactory.php

33 lines
838 B
PHP

<?php
namespace Database\Factories;
use App\Models\Client;
use App\Models\Contact;
use Illuminate\Database\Eloquent\Factories\Factory;
class ContactFactory extends Factory
{
protected $model = Contact::class;
public function definition(): array
{
return [
'first_name' => $this->faker->firstName(),
'last_name' => $this->faker->lastName(),
'email' => $this->faker->unique()->safeEmail(),
'phone' => $this->faker->phoneNumber(),
];
}
public function withClient(?Client $client = null): static
{
return $this->afterCreating(function (Contact $contact) use ($client) {
$contact->clients()->attach(
$client ?? Client::factory()->create(),
['is_primary' => true]
);
});
}
}