From 7a605616a04da363b36fa73f10f74ee054991f27 Mon Sep 17 00:00:00 2001 From: Alexej Krzewitzki Date: Wed, 26 Feb 2020 17:56:35 +0100 Subject: [PATCH] Updated readme and changelog --- changelog.md | 12 ++++++++++++ readme.md | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index 61c5735..2c6292e 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,17 @@ ## Version History +### v. 1.4.7 + +- added option for working with polymorphic translations + +### v. 1.4.6 + +- fixed support for Laravel 6 + +### v. 1.4.5 + +- Fixed a bug where fallback translations weren't being loaded. + ### v. 1.4.4 - added optional middleware setting diff --git a/readme.md b/readme.md index 2df0d55..f8d79af 100644 --- a/readme.md +++ b/readme.md @@ -322,13 +322,41 @@ use Illuminate\Database\Eloquent\Model as Eloquent; class Country extends Eloquent { - use TranslatableDB; + use TranslatableDB\TranslatableDB; - public $translationModel = 'MyApp\Models\CountryAwesomeTranslation'; + public $translationModel = MyApp\Models\CountryAwesomeTranslation::class; } ``` +## Polymorphic translations + +Sometimes translations are in a polymorphic table. In order to make this work you +need to make the following changes to your model. + +```php + +namespace MyApp\Models; + +use Flobbos\TranslatableDB\TranslatableDB; +use Flobbos\TranslatableDB\Contracts\PolyTrans; +use Illuminate\Database\Eloquent\Model as Eloquent; + +class Country extends Eloquent implements PolyTrans +{ + use TranslatableDB; + + public $translationModel = MyApp\Models\CountryAwesomeTranslation::class; + //Set your polymorphic key here + protected $translationForeignKey = 'translatable'; +} +``` + +By implementing the PolyTrans contract TranslatableDB knows that it needs to +handle translations differently. The translation key needs to be set as well +because otherwise TranslatableDB will assume the key automatically which doesn't +work with a polymorphic relationship. + ## Middleware ### Default