dimsav / laravel-translatable

[Deprecated] A Laravel package for multilingual models
MIT License
1.95k stars 320 forks source link

Changing model name #532

Closed mrcatman closed 5 years ago

mrcatman commented 6 years ago

I'm using non-standard model name ("CaseModel") because "case" is a reserved word in PHP. My model looks like:

namespace App;

use Dimsav\Translatable\Translatable;
use Illuminate\Database\Eloquent\Model;

class CaseModel extends Model
{
    use Translatable;
    public $table = "cases";
    public $translationModel = 'App\CaseTranslation';
    public $translatedAttributes = ['link','title','description'];
}

But when I try to save a model, an error appears:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'case_translations.case_model_id' in 'where clause' 

How can I change "case_model_id" to "case_id" here?

Gummibeer commented 6 years ago

Hey @mrcatman ,

This method returns the foreign key used by the relationship. So you can modify $translationForeignKey.

https://github.com/dimsav/laravel-translatable/blob/cf6c8dcdbb5bbe1166d252952281a34b45c10ac7/src/Translatable/Translatable.php#L134-L145

fawel11 commented 5 years ago

Great!

dimsav commented 5 years ago

As announced here, the project has been deprecated. Please use astrotomic/laravel-translatable.