2023-08-22 10:01:47 +02:00
|
|
|
<?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;
|
2023-08-22 10:01:47 +02:00
|
|
|
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
|
2023-08-22 10:01:47 +02:00
|
|
|
{
|
|
|
|
|
$mandatoryLocales = ['fr', 'en', 'de', 'nl'];
|
2023-08-23 09:44:51 +02:00
|
|
|
$name = $this->faker->unique()->company;
|
2023-08-22 10:01:47 +02:00
|
|
|
$type = \collect(InputTypeEnum::toArray())->random();
|
|
|
|
|
$details = null;
|
|
|
|
|
if (
|
|
|
|
|
\in_array($type, [
|
2025-05-20 10:16:12 +02:00
|
|
|
InputTypeEnum::selectMultiple,
|
|
|
|
|
InputTypeEnum::select,
|
|
|
|
|
InputTypeEnum::radio,
|
|
|
|
|
InputTypeEnum::checkbox
|
2023-08-22 10:01:47 +02:00
|
|
|
])
|
|
|
|
|
) {
|
|
|
|
|
$details = $this->faker->words(\count($mandatoryLocales));
|
|
|
|
|
}
|
|
|
|
|
return [
|
2025-05-20 10:16:12 +02:00
|
|
|
'type' => $type,
|
|
|
|
|
'name' => $name,
|
|
|
|
|
'slug' => Str::of($name)->slug(),
|
2023-08-22 10:01:47 +02:00
|
|
|
'placeholder' => \collect($mandatoryLocales)->mapWithKeys(function ($locale) {
|
|
|
|
|
return [$locale => "{$locale} {$this->faker->company}"];
|
|
|
|
|
})->all(),
|
2025-05-20 10:16:12 +02:00
|
|
|
'details' => !empty($details) ? \collect($details)->map(function ($word) use ($mandatoryLocales) {
|
2023-08-22 10:01:47 +02:00
|
|
|
return \collect($mandatoryLocales)->mapWithKeys(function ($locale) use ($word) {
|
|
|
|
|
return [$locale => "{$locale} {$word}"];
|
|
|
|
|
})->all();
|
2023-08-23 09:44:51 +02:00
|
|
|
})->all() : null,
|
2025-05-20 10:16:12 +02:00
|
|
|
'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'),
|
2023-08-22 10:01:47 +02:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|