90 lines
2.8 KiB
PHP
90 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Models\CmsArticle;
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Facades\Lang;
|
|
|
|
class CmsArticleSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Numerische IDs aus resources/lang/{locale}/b2in.php → Slugs für cms_articles.slug
|
|
*
|
|
* @var array<int, string>
|
|
*/
|
|
private const ARTICLE_ID_TO_SLUG = [
|
|
1 => 'escrow-system-dubai-investoren',
|
|
2 => 'spotlight-al-jaddaf-hotspot',
|
|
3 => 'turnkey-investments-moeblierung-rendite',
|
|
4 => 'supply-chain-management-vertragssicherheit',
|
|
5 => 'local-for-local-regionaler-moebelhandel',
|
|
];
|
|
|
|
public function run(): void
|
|
{
|
|
foreach ($this->getArticles() as $i => $data) {
|
|
CmsArticle::query()->updateOrCreate(
|
|
['slug' => $data['slug']],
|
|
array_merge($data, ['order' => $i + 1]),
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return array<int, array<string, mixed>>
|
|
*/
|
|
private function getArticles(): array
|
|
{
|
|
/** @var array<int, array<string, mixed>> $articlesDe */
|
|
$articlesDe = Lang::get('b2in.articles', [], 'de');
|
|
/** @var array<int, array<string, mixed>> $articlesEn */
|
|
$articlesEn = Lang::get('b2in.articles', [], 'en');
|
|
|
|
if (! is_array($articlesDe) || $articlesDe === []) {
|
|
return [];
|
|
}
|
|
|
|
if (! is_array($articlesEn)) {
|
|
$articlesEn = [];
|
|
}
|
|
|
|
ksort($articlesDe);
|
|
|
|
$out = [];
|
|
|
|
foreach ($articlesDe as $id => $rowDe) {
|
|
$id = (int) $id;
|
|
$slug = self::ARTICLE_ID_TO_SLUG[$id] ?? null;
|
|
if ($slug === null) {
|
|
continue;
|
|
}
|
|
|
|
$rowEn = $articlesEn[$id] ?? $rowDe;
|
|
|
|
$out[] = [
|
|
'slug' => $slug,
|
|
'title' => [
|
|
'de' => (string) ($rowDe['title'] ?? ''),
|
|
'en' => (string) ($rowEn['title'] ?? ''),
|
|
],
|
|
'subtitle' => [
|
|
'de' => (string) ($rowDe['subtitle'] ?? ''),
|
|
'en' => (string) ($rowEn['subtitle'] ?? ''),
|
|
],
|
|
'image' => (string) ($rowDe['image'] ?? ''),
|
|
'category' => (string) ($rowDe['category'] ?? ''),
|
|
'date_label' => (string) ($rowDe['date'] ?? ''),
|
|
'read_time' => (string) ($rowDe['readTime'] ?? ''),
|
|
'author' => is_array($rowDe['author'] ?? null) ? $rowDe['author'] : [],
|
|
'content' => [
|
|
'de' => is_array($rowDe['content'] ?? null) ? $rowDe['content'] : [],
|
|
'en' => is_array($rowEn['content'] ?? null) ? $rowEn['content'] : [],
|
|
],
|
|
'is_published' => true,
|
|
];
|
|
}
|
|
|
|
return $out;
|
|
}
|
|
}
|