Support the ongoing development of Laravel.io →
Database Eloquent Packages
Last updated 1 year ago.
0

Hey, thanks a lot, this is exactly what i was looking for!

Last updated 1 year ago.
0

You are welcome :)

Last updated 1 year ago.
0

You saved my day. Tnx a lot.

Last updated 1 year ago.
0

Hi, I have a little problem with your package in Laravel... but I'm not so skilled with MVC and OOP so, please excuse me for my stupid problem. Therefore, I need to create a table with this schema:

// /app/database/migration/..._create_pages_table.php
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreatePagesTable extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create('pages', function(Blueprint $table)
		{
                    $table->increments('id');
                     $table->string('code');
		});
		Schema::create('page_translations', function(Blueprint $table)
		{
	            $table->increments('id');
		    $table->integer('page_id')->unsigned();
		    $table->string('title')->nullable();
                    $table->string('locale')->index();
		    $table->unique(['page_id','locale']);
		    $table->foreign('page_id')->references('id')->on('pages');
		});	
  }

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
			Schema::drop('pages');
			Schema::drop('page_translations');
	}

}

Then, I launch the migration and I create 2 files:

// /apps/models/Page.php
<?php
class Page extends Eloquent { 
    
    use \Dimsav\Translatable\Translatable;
    
    public $translatedAttributes = array('name');    
    protected $fillable = ['code', 'title'];

}

and

// /apps/models/PageTranslation.php
<?php

class PageTranslation extends Eloquent {

    public $timestamps = false;
    protected $fillable = ['title'];

}

Then, I insert some data into the tables and then... how can I retrieve the correct title into a view? I tried with "$page->en->title" but appear a message "Class 'App\Models\PageTranslation' not found".

Where am I wrong? Any ideas? Thanks.

Last updated 1 year ago.
0

Thanks for this package. Fits my needs perfectly!

Last updated 1 year ago.
0

Hi orizzonti,

your question is not related to the package. The error message "Class not found" occurs when the class is not properly autoloaded.

Last updated 1 year ago.
0

Ok, thank you dimsav.

Last updated 1 year ago.
0

so far im very satisfied with this package, i am just starting a new project that supports a couple of languages .. i have a simple question how can i get a all translation for an inserted record in case i want to display all available translations?

i have a News Module. so $news = News::all(); won't return all the news with all their translations

Last updated 1 year ago.
0

Hi samirgit!

I am glad you are satisfied with laravel translatable. Your question however is related to laravel and not to the package.

For performance reasons, relationships are not loaded in laravel by default. To force laravel loading the translations use this instead:

News::withTranslations()->get();

If you need any help for using laravel translatable, it is helpful to have a look at the tests.

Please open an issue in github for questions related to the package, I don't get any notifications for answers in this topic. Also, if you post on github, other users having an issue, will be able to check the conversations in the issues area of the package.

Last updated 1 year ago.
0

dimsav said:

Hello community,

I would like to share with you my first package laravel-translatable

This is a Laravel package for translatable models. Its goal is to remove the complexity in retrieving and storing multilingual model instances. With this package you write less code, as the translations are being managed automatically behind the scenes.

If you want to store translations of your models into the database, this package is for you.

It would be awesome to receive some feedback/requests.

Last updated 1 year ago.
0

Hi Dimsav

When i m installing dimsav/laravel-translatable package i m getting the error of the requested package of dimsav/laravel-translatable could not be found in any version of , there may be a typo in the package name.

"require": { "dimsav/laravel-translatable": "5.*-dev" }

Thanks Harsh Shah

Last updated 1 year ago.
0

Hi harshpareshkumarshah,

this: "require": { "dimsav/laravel-translatable": "5.*-dev" }

is for the laravel-5 which is currently on beta.

Just run "composer require dimsav/laravel-translatable" to get the right version for your laravel installation. I just updated the readme file to avoid future confusion about this.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

dimsav dimsav Joined 31 Jan 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.