ldc-com-app-bo/database/factories/FormularyFactory.php

53 lines
1.8 KiB
PHP
Raw Permalink Normal View History

<?php
namespace Database\Factories;
use App\Enums\Formularies\InputStatusEnum;
use App\Enums\Formularies\InputTypeEnum;
2025-05-20 16:20:23 +02:00
use App\Models\Tenant;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
class FormularyFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array
*/
2025-05-20 16:20:23 +02:00
public function definition(): array
{
$mandatoryLocales = ['fr', 'en', 'de', 'nl'];
$name = $this->faker->unique()->company;
$type = \collect(InputTypeEnum::toArray())->random();
$details = null;
if (
\in_array($type, [
InputTypeEnum::selectMultiple,
InputTypeEnum::select,
InputTypeEnum::radio,
InputTypeEnum::checkbox
])
) {
$details = $this->faker->words(\count($mandatoryLocales));
}
return [
'type' => $type,
'name' => $name,
'slug' => Str::of($name)->slug(),
'placeholder' => \collect($mandatoryLocales)->mapWithKeys(function ($locale) {
return [$locale => "{$locale} {$this->faker->company}"];
})->all(),
'details' => !empty($details) ? \collect($details)->map(function ($word) use ($mandatoryLocales) {
return \collect($mandatoryLocales)->mapWithKeys(function ($locale) use ($word) {
return [$locale => "{$locale} {$word}"];
})->all();
})->all() : null,
'is_visible' => $this->faker->boolean(75),
'required' => $this->faker->boolean(75),
'status' => InputStatusEnum::default,
2025-05-20 16:20:23 +02:00
'tenant_id' => Tenant::query()->first('id'),
];
}
}