52 lines
1.5 KiB
PHP
52 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\GitlabProject;
|
|
use App\Models\Site;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
use Uwil\LaravelBackend\Support\UserRoleRegistry;
|
|
|
|
/**
|
|
* Factory for generating Site model instances with randomized data.
|
|
*
|
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Site>
|
|
*/
|
|
class SiteFactory extends Factory
|
|
{
|
|
/**
|
|
* Associated model.
|
|
*
|
|
* @var class-string<\App\Models\Site>
|
|
*/
|
|
#[\Override]
|
|
protected $model = Site::class;
|
|
|
|
/**
|
|
* Define the model's default state.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function definition(): array
|
|
{
|
|
// Get random project manager or create one.
|
|
$enumValue = UserRoleRegistry::get('project-manager')->value;
|
|
$projectManager = User::getModelsCached()
|
|
->where('published', true)
|
|
->where('role', $enumValue)
|
|
->shuffle()
|
|
->first() ?? User::factory()->create([
|
|
'published' => true,
|
|
'role' => $enumValue,
|
|
]);
|
|
|
|
return [
|
|
"name" => fake()->unique()->words(3, true),
|
|
"url_re7" => fake()->boolean(75) ? fake()->unique()->url() : null,
|
|
"url_prod" => fake()->boolean(75) ? fake()->unique()->url() : null,
|
|
"project_manager_id" => fake()->boolean(75) ? $projectManager->getKey() : null,
|
|
"gitlab_project_id" => GitlabProject::factory(),
|
|
];
|
|
}
|
|
}
|