How do I eager load with() or similar when I have the situation like below. posts with post_translation Schemas. Laravel.
I have implemented laravel localization with multilanguage architecture regarding this tutorial (https://mydnic.be/post/how-to-build-an-efficient-and-seo-friendly-multilingual-architecture-for-your-laravel-application), and now when I output data in view, for every data I have now 2 queries (duplicated) queries, because of tag_translation Schema into Tag database and localize for 2 language. How to eager load this to show only related queries not duplicated.?!
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateTagsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('tags', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
});
Schema::create('tag_translations', function (Blueprint $table) {
$table->increments('id');
$table->integer('tag_id')->unsigned();
$table->string('locale')->index();
// The actual fields to store the content of your entity. You can add whatever you need.
$table->string('name');
$table->string('slug')->unique();
$table->unique(['tag_id', 'locale']);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('tags');
Schema::dropIfExists('tag_translations');
}
}
Other example of queries number:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateTagsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('tags', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
});
Schema::create('tag_translations', function (Blueprint $table) {
$table->increments('id');
$table->integer('tag_id')->unsigned();
$table->string('locale')->index();
// The actual fields to store the content of your entity. You can add whatever you need.
$table->string('name');
$table->string('slug')->unique();
$table->unique(['tag_id', 'locale']);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('tags');
Schema::dropIfExists('tag_translations');
}
}
Thanks on help!
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire