ldc-groupe/database/seeders/AddHeroConfigSeeder.php

125 lines
4.9 KiB
PHP

<?php
namespace Database\Seeders;
use App\Models\PageConfig;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class AddHeroConfigSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run(): void
{
// php artisan db:seed --class=AddHeroConfigSeeder
$ids = ['39'];
$configs = PageConfig::whereIn('id', $ids)->get();
$localesToPopulate = ['fr', "en"];
foreach($localesToPopulate as $locale) {
app()->setLocale($locale);
$newObject = [
"key" => "list_hero",
"order" => 100,
"type" => 9,
"label" => "Hero Section",
"validation" => "required|array|min:1|max:1",
"children" => [
[
"key" => "string_hero_title",
"order" => 1,
"type" => 1,
"label" => $locale === "fr" ? "Titre": "Title",
"validation" => "nullable|string|max:255",
"children" => []
],
[
"key" => "string_hero_subtitle",
"order" => 2,
"type" => 1,
"label" => $locale === "fr" ? "Sous-titre" : "Subtitle",
"validation" => "nullable|string|max:255"
],
[
"key" => "wysiwyg_hero_description",
"order" => 3,
"type" => 3,
"label" => "Description",
"validation" => "nullable|string|min:15|max:400"
],
[
"key" => "list_hero_cta",
"order" => 4,
"type" => 9,
"label" => "CTA",
"validation" => "nullable|array|min:0|max:1",
"children" => [
[
"key" => "string_hero_cta_label",
"order" => 1,
"type" => 1,
"label" => "Label",
"validation" => "required|string|min:1|max:60",
"children" => []
],
[
"key" => "string_hero_cta_url",
"order" => 2,
"type" => 1,
"label" => "URL",
"validation" => "required|string|min:1|max:255",
"children" => []
]
]
],
[
"key" => "list_media_list",
"order" => 5,
"type" => 9,
"label" => $locale === "fr" ? "Médias" : "Medias",
"validation" => "required|array|min:1|max:5",
"children" => [
[
"key" => "string_local_video",
"order" => 1,
"type" => 1,
"label" => $locale === "fr" ? "Vidéo Locale" : "Local Video",
"validation" => "nullable|string|max:255"
],
[
"key" => "image_picture",
"order" => 2,
"type" => 8,
"label" => "Image",
"validation" => "nullable|file|mimes:jpg,jpeg,png,webp|max:5120|dimensions:width=1600,height=768"
],
[
"key" => "string_media_alt",
"order" => 3,
"type" => 1,
"label" => $locale === "fr" ? "Champ Alternatif" : "Text Alt",
"validation" => "required|string|between:3,255",
"children" => []
]
]
]
]
];
foreach ($configs as $config) {
$configTranslations = $config->getTranslations('config');
$configData = $configTranslations[$locale] ?? [];
$configData[] = $newObject;
$configTranslations[$locale] = $configData;
$config->setTranslations('config', $configTranslations);
$config->save();
}
}
}
}