100 lines
3.4 KiB
PHP
100 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Enums\Portal;
|
|
use App\Models\Category;
|
|
use Illuminate\Database\Seeder;
|
|
|
|
class CategorySeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*/
|
|
public function run(): void
|
|
{
|
|
$categories = [
|
|
[
|
|
'key' => 'news-wirtschaft',
|
|
'portal' => Portal::Both,
|
|
'translations' => [
|
|
'de' => [
|
|
'name' => 'Wirtschaft',
|
|
'slug' => 'wirtschaft',
|
|
'description' => 'Pressemitteilungen aus Wirtschaft und Unternehmen.',
|
|
],
|
|
'en' => [
|
|
'name' => 'Business',
|
|
'slug' => 'business',
|
|
'description' => 'Press releases from business and companies.',
|
|
],
|
|
],
|
|
],
|
|
[
|
|
'key' => 'news-technologie',
|
|
'portal' => Portal::Both,
|
|
'translations' => [
|
|
'de' => [
|
|
'name' => 'Technologie',
|
|
'slug' => 'technologie',
|
|
'description' => 'News rund um Innovation, IT und digitale Themen.',
|
|
],
|
|
'en' => [
|
|
'name' => 'Technology',
|
|
'slug' => 'technology',
|
|
'description' => 'News around innovation, IT, and digital topics.',
|
|
],
|
|
],
|
|
],
|
|
[
|
|
'key' => 'news-finanzen',
|
|
'portal' => Portal::Both,
|
|
'translations' => [
|
|
'de' => [
|
|
'name' => 'Finanzen',
|
|
'slug' => 'finanzen',
|
|
'description' => 'Pressemitteilungen zu Banken, Boerse und Finanzthemen.',
|
|
],
|
|
'en' => [
|
|
'name' => 'Finance',
|
|
'slug' => 'finance',
|
|
'description' => 'Press releases about banks, stock markets, and finance topics.',
|
|
],
|
|
],
|
|
],
|
|
];
|
|
|
|
foreach ($categories as $categoryData) {
|
|
$deSlug = $categoryData['translations']['de']['slug'];
|
|
|
|
$category = Category::query()
|
|
->whereHas('translations', function ($query) use ($deSlug) {
|
|
$query->where('locale', 'de')->where('slug', $deSlug);
|
|
})
|
|
->first();
|
|
|
|
if (! $category) {
|
|
$category = Category::query()->create([
|
|
'portal' => $categoryData['portal']->value,
|
|
'is_active' => true,
|
|
]);
|
|
} else {
|
|
$category->update([
|
|
'portal' => $categoryData['portal']->value,
|
|
'is_active' => true,
|
|
]);
|
|
}
|
|
|
|
foreach ($categoryData['translations'] as $locale => $translation) {
|
|
$category->translations()->updateOrCreate(
|
|
['locale' => $locale],
|
|
[
|
|
'name' => $translation['name'],
|
|
'slug' => $translation['slug'],
|
|
'description' => $translation['description'],
|
|
]
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|