Files
solidtime/database/factories/OrganizationFactory.php
2024-10-01 22:48:27 +02:00

61 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace Database\Factories;
use App\Models\Organization;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends Factory<Organization>
*/
class OrganizationFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'name' => $this->faker->unique()->company(),
'currency' => $this->faker->currencyCode(),
'billable_rate' => null,
'user_id' => User::factory(),
'personal_team' => true,
'employees_can_see_billable_rates' => false,
];
}
public function billableRate(?int $billableRate): self
{
return $this->state(fn (array $attributes) => [
'billable_rate' => $billableRate,
]);
}
public function withBillableRate(): self
{
return $this->state(fn (array $attributes) => [
'billable_rate' => $this->faker->numberBetween(50, 1000) * 100,
]);
}
public function withOwner(?User $owner = null): self
{
return $this->state(fn (array $attributes) => [
'user_id' => $owner === null ? User::factory() : $owner->getKey(),
]);
}
public function withFakeId(): self
{
return $this->state(fn (array $attributes) => [
'id' => $this->faker->uuid(),
]);
}
}