定制 megaezz/laravel-eloquent-localizable 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

megaezz/laravel-eloquent-localizable

最新稳定版本:v1.0.0

Composer 安装命令:

composer require megaezz/laravel-eloquent-localizable

包简介

Retrieve the value of a localizable attribute based on the current locale.

README 文档

README

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.

Installation

  1. Install the package via Composer:
composer require megaezz/laravel-eloquent-localizable
  1. Apply the Localizable trait to your Eloquent model:
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';
}

Make sure your database table contains the necessary fields for each localized attribute. For example:

•	title_en, title_ru
•	description_en, description_ru

Retrieving Localized Attributes

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

统计信息

  • 总下载量: 27
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-16