2.1-2.4: install spatie/laravel-translatable, migrate to JSON, update models & controllers
Deploy Backend / deploy (push) Failing after 1m52s
Deploy Backend / deploy (push) Failing after 1m52s
This commit is contained in:
1 parent
75af8220a7
commit
37dd2c9d54
17 files changed
+453
-285
No files matched your search
@@ -0,0 +1,248 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
// === WEBSITE TABLES ===
|
||||
|
||||
// website_about_me
|
||||
Schema::table('website_about_me', function (Blueprint $table) {
|
||||
$table->json('translations')->nullable()->after('image');
|
||||
});
|
||||
$rows = DB::table('website_about_me_translations')->get();
|
||||
foreach ($rows->groupBy('about_me_id') as $aboutMeId => $translations) {
|
||||
$data = [];
|
||||
foreach ($translations as $t) {
|
||||
$data['title'][$t->locale] = $t->title;
|
||||
$data['description'][$t->locale] = $t->description;
|
||||
}
|
||||
DB::table('website_about_me')->where('id', $aboutMeId)->update(['translations' => json_encode($data)]);
|
||||
}
|
||||
Schema::dropIfExists('website_about_me_translations');
|
||||
|
||||
// website_skills
|
||||
Schema::table('website_skills', function (Blueprint $table) {
|
||||
$table->json('translations')->nullable()->after('percentage');
|
||||
});
|
||||
$rows = DB::table('website_skill_translations')->get();
|
||||
foreach ($rows->groupBy('skill_id') as $skillId => $translations) {
|
||||
$data = [];
|
||||
foreach ($translations as $t) {
|
||||
$data['title'][$t->locale] = $t->title;
|
||||
$data['description'][$t->locale] = $t->description;
|
||||
}
|
||||
DB::table('website_skills')->where('id', $skillId)->update(['translations' => json_encode($data)]);
|
||||
}
|
||||
Schema::dropIfExists('website_skill_translations');
|
||||
|
||||
// website_services
|
||||
Schema::table('website_services', function (Blueprint $table) {
|
||||
$table->json('translations')->nullable()->after('imageSrc');
|
||||
});
|
||||
$rows = DB::table('website_service_translations')->get();
|
||||
foreach ($rows->groupBy('service_id') as $serviceId => $translations) {
|
||||
$data = [];
|
||||
foreach ($translations as $t) {
|
||||
$data['title'][$t->locale] = $t->title;
|
||||
$data['description'][$t->locale] = $t->description;
|
||||
}
|
||||
DB::table('website_services')->where('id', $serviceId)->update(['translations' => json_encode($data)]);
|
||||
}
|
||||
Schema::dropIfExists('website_service_translations');
|
||||
|
||||
// website_project_categories
|
||||
Schema::table('website_project_categories', function (Blueprint $table) {
|
||||
$table->json('translations')->nullable()->after('image');
|
||||
});
|
||||
$rows = DB::table('website_project_category_translations')->get();
|
||||
foreach ($rows->groupBy('category_id') as $categoryId => $translations) {
|
||||
$data = [];
|
||||
foreach ($translations as $t) {
|
||||
$data['title'][$t->locale] = $t->title;
|
||||
$data['description'][$t->locale] = $t->description;
|
||||
}
|
||||
DB::table('website_project_categories')->where('id', $categoryId)->update(['translations' => json_encode($data)]);
|
||||
}
|
||||
Schema::dropIfExists('website_project_category_translations');
|
||||
|
||||
// website_projects
|
||||
Schema::table('website_projects', function (Blueprint $table) {
|
||||
$table->json('translations')->nullable()->after('image2');
|
||||
});
|
||||
$rows = DB::table('website_project_translations')->get();
|
||||
foreach ($rows->groupBy('project_id') as $projectId => $translations) {
|
||||
$data = [];
|
||||
foreach ($translations as $t) {
|
||||
$data['title'][$t->locale] = $t->title;
|
||||
$data['description'][$t->locale] = $t->description;
|
||||
}
|
||||
DB::table('website_projects')->where('id', $projectId)->update(['translations' => json_encode($data)]);
|
||||
}
|
||||
Schema::dropIfExists('website_project_translations');
|
||||
|
||||
// === BLOG TABLES ===
|
||||
Schema::table('posts', function (Blueprint $table) {
|
||||
$table->json('translations')->nullable()->after('featured_image');
|
||||
});
|
||||
Schema::table('categories', function (Blueprint $table) {
|
||||
$table->json('translations')->nullable()->after('image');
|
||||
});
|
||||
Schema::table('tags', function (Blueprint $table) {
|
||||
$table->json('translations')->nullable()->after('slug');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
// Restore website_about_me_translations
|
||||
Schema::create('website_about_me_translations', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('about_me_id');
|
||||
$table->string('locale')->index();
|
||||
$table->string('title');
|
||||
$table->text('description');
|
||||
$table->timestamps();
|
||||
$table->foreign('about_me_id')->references('id')->on('website_about_me')->onDelete('cascade');
|
||||
$table->unique(['about_me_id', 'locale']);
|
||||
});
|
||||
DB::table('website_about_me')->whereNotNull('translations')->each(function ($row) {
|
||||
$translations = json_decode($row->translations, true);
|
||||
if (!$translations) return;
|
||||
foreach (($translations['title'] ?? []) as $locale => $title) {
|
||||
DB::table('website_about_me_translations')->insert([
|
||||
'about_me_id' => $row->id,
|
||||
'locale' => $locale,
|
||||
'title' => $title,
|
||||
'description' => $translations['description'][$locale] ?? '',
|
||||
]);
|
||||
}
|
||||
});
|
||||
Schema::table('website_about_me', function (Blueprint $table) {
|
||||
$table->dropColumn('translations');
|
||||
});
|
||||
|
||||
// Restore website_skill_translations
|
||||
Schema::create('website_skill_translations', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('skill_id')->constrained('website_skills')->onDelete('cascade');
|
||||
$table->string('locale')->index();
|
||||
$table->string('title');
|
||||
$table->text('description');
|
||||
$table->unique(['skill_id', 'locale']);
|
||||
$table->timestamps();
|
||||
});
|
||||
DB::table('website_skills')->whereNotNull('translations')->each(function ($row) {
|
||||
$translations = json_decode($row->translations, true);
|
||||
if (!$translations) return;
|
||||
foreach (($translations['title'] ?? []) as $locale => $title) {
|
||||
DB::table('website_skill_translations')->insert([
|
||||
'skill_id' => $row->id,
|
||||
'locale' => $locale,
|
||||
'title' => $title,
|
||||
'description' => $translations['description'][$locale] ?? '',
|
||||
]);
|
||||
}
|
||||
});
|
||||
Schema::table('website_skills', function (Blueprint $table) {
|
||||
$table->dropColumn('translations');
|
||||
});
|
||||
|
||||
// Restore website_service_translations
|
||||
Schema::create('website_service_translations', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('service_id');
|
||||
$table->string('locale')->index();
|
||||
$table->string('title');
|
||||
$table->text('description');
|
||||
$table->timestamps();
|
||||
$table->foreign('service_id')->references('id')->on('website_services')->onDelete('cascade');
|
||||
$table->unique(['service_id', 'locale']);
|
||||
});
|
||||
DB::table('website_services')->whereNotNull('translations')->each(function ($row) {
|
||||
$translations = json_decode($row->translations, true);
|
||||
if (!$translations) return;
|
||||
foreach (($translations['title'] ?? []) as $locale => $title) {
|
||||
DB::table('website_service_translations')->insert([
|
||||
'service_id' => $row->id,
|
||||
'locale' => $locale,
|
||||
'title' => $title,
|
||||
'description' => $translations['description'][$locale] ?? '',
|
||||
]);
|
||||
}
|
||||
});
|
||||
Schema::table('website_services', function (Blueprint $table) {
|
||||
$table->dropColumn('translations');
|
||||
});
|
||||
|
||||
// Restore website_project_category_translations
|
||||
Schema::create('website_project_category_translations', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('category_id');
|
||||
$table->string('locale')->index();
|
||||
$table->string('title');
|
||||
$table->text('description');
|
||||
$table->timestamps();
|
||||
$table->foreign('category_id')->references('id')->on('website_project_categories')->onDelete('cascade');
|
||||
$table->unique(['category_id', 'locale']);
|
||||
});
|
||||
DB::table('website_project_categories')->whereNotNull('translations')->each(function ($row) {
|
||||
$translations = json_decode($row->translations, true);
|
||||
if (!$translations) return;
|
||||
foreach (($translations['title'] ?? []) as $locale => $title) {
|
||||
DB::table('website_project_category_translations')->insert([
|
||||
'category_id' => $row->id,
|
||||
'locale' => $locale,
|
||||
'title' => $title,
|
||||
'description' => $translations['description'][$locale] ?? '',
|
||||
]);
|
||||
}
|
||||
});
|
||||
Schema::table('website_project_categories', function (Blueprint $table) {
|
||||
$table->dropColumn('translations');
|
||||
});
|
||||
|
||||
// Restore website_project_translations
|
||||
Schema::create('website_project_translations', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('project_id');
|
||||
$table->string('locale')->index();
|
||||
$table->string('title');
|
||||
$table->text('description');
|
||||
$table->timestamps();
|
||||
$table->foreign('project_id')->references('id')->on('website_projects')->onDelete('cascade');
|
||||
$table->unique(['project_id', 'locale']);
|
||||
});
|
||||
DB::table('website_projects')->whereNotNull('translations')->each(function ($row) {
|
||||
$translations = json_decode($row->translations, true);
|
||||
if (!$translations) return;
|
||||
foreach (($translations['title'] ?? []) as $locale => $title) {
|
||||
DB::table('website_project_translations')->insert([
|
||||
'project_id' => $row->id,
|
||||
'locale' => $locale,
|
||||
'title' => $title,
|
||||
'description' => $translations['description'][$locale] ?? '',
|
||||
]);
|
||||
}
|
||||
});
|
||||
Schema::table('website_projects', function (Blueprint $table) {
|
||||
$table->dropColumn('translations');
|
||||
});
|
||||
|
||||
// Blog tables
|
||||
Schema::table('posts', function (Blueprint $table) {
|
||||
$table->dropColumn('translations');
|
||||
});
|
||||
Schema::table('categories', function (Blueprint $table) {
|
||||
$table->dropColumn('translations');
|
||||
});
|
||||
Schema::table('tags', function (Blueprint $table) {
|
||||
$table->dropColumn('translations');
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user