- formulary api output - Formulary seeder slug unique - rename Formulary visible column because the prop is hidden by Model trait Concerns\HideAttributes - mandatory input phone was not type of phone - form factory to be status default - formulary factory type
48 lines
1.7 KiB
PHP
48 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Enums\Formularies\InputStatusEnum;
|
|
use App\Enums\Formularies\InputTypeEnum;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
use Illuminate\Support\Str;
|
|
|
|
class FormularyFactory extends Factory
|
|
{
|
|
/**
|
|
* Define the model's default state.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function definition()
|
|
{
|
|
$mandatoryLocales = ['fr', 'en', 'de', 'nl'];
|
|
$name = $this->faker->unique()->company;
|
|
$type = \collect(InputTypeEnum::toArray())->random();
|
|
$details = null;
|
|
if (
|
|
\in_array($type, [
|
|
InputTypeEnum::multipleselect(), 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(),
|
|
];
|
|
}
|
|
}
|