djc-new/database/seeders/KeywordSeeder.php

56 lines
1.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace Database\Seeders;
use App\Models\Keyword;
use Illuminate\Database\Seeder;
use Illuminate\Support\Arr;
class KeywordSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Keyword::truncate();
$list = [
['key' => 'article_category', 'name' => '文章分类', 'list' => []],
//标签value填写色号指定标签颜色
['key' => 'article_tag', 'name' => '文章标签', 'list' => []],
['key' => 'banner_address', 'name' => '广告位置', 'list' => []],
['key' => 'financial_cate', 'name' => '财务报表类型', 'list' => []],
['key' => 'file_cate', 'name' => '档案类型', 'list' => []],
['key' => 'department', 'name' => '部门管理', 'list' => []],
['key' => 'area_cate', 'name' => '地区类型', 'list' => []],
['key' => 'organized_body', 'name' => '社别管理', 'list' => []],
['key' => 'housing_estate', 'name' => '小区管理', 'list' => []],
];
foreach ($list as $item) {
$type = Keyword::create(Arr::except($item, 'list'));
if (isset($item['list'])) {
$keywords = [];
foreach ($item['list'] as $index => $name) {
$template = [
'key' => $type->key . ($index + 1),
'parent_key' => $type->key,
'lv' => $type->lv + 1,
'sort' => $index + 1
];
if (is_array($name)) {
$template = array_merge($template, $name);
} else {
$template['name'] = $name;
}
array_push($keywords, $template);
}
$type->children()->createMany($keywords);
}
}
}
}