27 lines
903 B
PHP
27 lines
903 B
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' => 'Нумерованный']
|
|
]
|
|
];
|
|
|
|
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]);
|
|
});
|
|
});
|
|
}
|
|
}
|