60 lines
1.7 KiB
PHP
60 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Models\Page;
|
|
use App\Models\SiteTranslation;
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
class HomeMenuTranslationsSeeder extends Seeder
|
|
{
|
|
public function run(): void
|
|
{
|
|
$data = require database_path('data/home_menu_translations.php');
|
|
|
|
foreach ($data['site'] as $key => $translations) {
|
|
$record = SiteTranslation::firstOrNew(['hash' => md5($key)]);
|
|
$existing = $record->translations ?? [];
|
|
|
|
$merged = array_merge($existing, [
|
|
'tr' => $key,
|
|
], array_filter($translations));
|
|
|
|
SiteTranslation::updateOrCreate(
|
|
['hash' => md5($key)],
|
|
[
|
|
'key' => $key,
|
|
'translations' => $merged,
|
|
]
|
|
);
|
|
}
|
|
|
|
foreach ($data['pages'] as $pageId => $fields) {
|
|
$page = Page::query()->whereKey($pageId)->first();
|
|
|
|
if (! $page) {
|
|
continue;
|
|
}
|
|
|
|
foreach ($fields as $fieldName => $translations) {
|
|
foreach ($translations as $languageCode => $value) {
|
|
if ($value === '') {
|
|
continue;
|
|
}
|
|
|
|
$page->setTranslation($fieldName, $languageCode, $value, 'published', 1);
|
|
}
|
|
|
|
if (! isset($translations['tr'])) {
|
|
$page->setTranslation($fieldName, 'tr', $page->{$fieldName}, 'published', 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
Cache::flush();
|
|
|
|
$this->command?->info('Home page and menu translations applied successfully.');
|
|
}
|
|
}
|