37 lines
1.5 KiB
PHP
37 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders\Dictionaries;
|
|
|
|
use App\Models\Dictionaries\Dictionary;
|
|
use Illuminate\Database\Seeder;
|
|
|
|
class DictionariesTableSeeder extends Seeder {
|
|
public array $dictionaries = [
|
|
'list-types' => [
|
|
'title' => 'Виды списка',
|
|
'items' => ['marked' => 'Маркированный', 'numeric' => 'Нумерованный']
|
|
],
|
|
'title-types' => [
|
|
'title' => 'Виды заголовков',
|
|
'items' => ['h2' => 'Заголовок 1', 'h3' => 'Заголовок 2', 'h4' => 'Заголовок 3']
|
|
],
|
|
'feedback-types' => [
|
|
'title' => 'Тема обращения',
|
|
'items' => [
|
|
'regulation' => 'Техническое нормирование', 'assessment' => 'Оценка пригодности', 'certification' => 'Добровольная сертификация', 'questions' => 'Вопросы нормирования и стандартизации', 'other' => 'Другие'
|
|
]
|
|
]
|
|
];
|
|
|
|
public function run() {
|
|
collect($this->dictionaries)->each(function($data, $name) {
|
|
$dictionary = Dictionary::firstOrCreate(['name' => $name]);
|
|
$dictionary->update(collect($data)->except('items')->all());
|
|
collect($data['items'] ?? [])->each(function($title, $name) use($dictionary) {
|
|
$item = $dictionary->items()->firstOrCreate(['name' => $name]);
|
|
$item->update(['title' => $title]);
|
|
});
|
|
});
|
|
}
|
|
}
|