Files
solidtime/database/factories/ClientFactory.php
T

47 lines
1.0 KiB
PHP

<?php
declare(strict_types=1);
namespace Database\Factories;
use App\Models\Client;
use App\Models\Organization;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends Factory<Client>
*/
class ClientFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'name' => $this->faker->company(),
'organization_id' => Organization::factory(),
];
}
public function forOrganization(Organization $organization): self
{
return $this->state(function (array $attributes) use ($organization) {
return [
'organization_id' => $organization->getKey(),
];
});
}
public function randomCreatedAt(): self
{
return $this->state(function (array $attributes): array {
return [
'created_at' => $this->faker->dateTimeBetween('-1 day', 'now'),
];
});
}
}