53 lines
2.3 KiB
PHP
53 lines
2.3 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' => 'Другие'
|
||
],
|
||
],
|
||
'operation-types' => [
|
||
'title' => 'Виды операций',
|
||
'items' => ['development' => 'Разработка', 'rework' => 'Пересмотр', 'modification' => 'Изменение']
|
||
],
|
||
'listings' => [
|
||
'title' => 'Перечни ПП',
|
||
'items' => ['pp1521' => 'ПП №1521 от 26.12.2014 г.', 'pp985' => 'ПП № 985 от 04.07.2020 г.', 'pp815' => 'ПП № 815 от 28.05.2021 г.']
|
||
],
|
||
'images-types' => [
|
||
'title' => 'Тип изображения',
|
||
'items' => ['full-width' => 'во всю ширину', 'tiles' => 'плиткой']
|
||
],
|
||
];
|
||
|
||
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]);
|
||
});
|
||
});
|
||
}
|
||
}
|