Retrieve the value of a localizable attribute based on the current locale.
megaezz/laravel-eloquent-localizable is a Laravel package for retrieve the value of a localizable attribute based on the current locale..
It currently has 0 GitHub stars and 105 downloads on Packagist (latest version v1.0.0).
Install it with composer require megaezz/laravel-eloquent-localizable.
Discover more Laravel packages by megaezz
or browse all Laravel packages to compare alternatives.
Last updated
A simple trait for making Eloquent models localizable in Laravel. This trait allows you to easily manage model attributes in different languages by using the current locale or a fallback locale.
composer require megaezz/laravel-eloquent-localizable
use Megaezz\LaravelEloquentLocalizable\Localizable;
class Article extends Model
{
use Localizable;
protected $localizable = ['title', 'description'];
// Optionally, specify fallback locale, or the one defined in app.locale will be used.
protected $fallback_locale = 'en';
}
• title_en, title_ru
• description_en, description_ru
Once the trait is applied, you can access the localizable attributes like usual. The value returned will be based on the current locale of the application:
$article->title; // Will return the title based on the current locale or fallback value
$article->description; // Will return the description based on the current locale or fallback value