10-04-2026
This commit is contained in:
parent
4d6b4930b2
commit
4bb89aad8c
836 changed files with 52961 additions and 5950 deletions
90
database/seeders/CmsArticleSeeder.php
Normal file
90
database/seeders/CmsArticleSeeder.php
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
<?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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue