mercredi 2 décembre 2015

laravel-translatable plugin using foreign key

I am using laravel 5 and http://ift.tt/1bE3b7a plugin. Is there a way I can reference locales table without having to set the name of locale in each column.

migrations for locale

        Schema::create('locales', function(Blueprint $table)
    {
        $table->increments('id');
        $table->string('code',5)->unique();
        $table->timestamps();
    });

migration for download table

    Schema::create('downloads', function(Blueprint $table)
    {
        $table->increments('id');
        $table->string('slug', 30);
        $table->unique('slug');
        $table->string('file');
        $table->boolean('online');
        $table->timestamps();
    });

    Schema::create('download_translations', function(Blueprint $table)
    {
        $table->increments('id');
        $table->unsignedInteger('download_id');
        $table->foreign('download_id')->references('id')->on('downloads')->onDelete('cascade');
        $table->unsignedInteger('locale_id');
        $table->foreign('locale_id')->references('id')->on('locales')->onDelete('cascade');

        $table->string('title');
        $table->text('text');



    });

I want to display all the translation when the user navigates to the correct locale.

route file

    Route::get('{locale}/download', function($locale) {
       app()->setLocale($locale);

       $article = Download::first();
    }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire