Files
solidtime/database/factories/TaskFactory.php
T
2024-01-21 19:52:19 +01:00

49 lines
1.1 KiB
PHP

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