latevaweb/laravel-translatable 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

latevaweb/laravel-translatable

最新稳定版本:0.1.9

Composer 安装命令:

composer require latevaweb/laravel-translatable

包简介

Laravel package to make Eloquent models attributes translatables

README 文档

README

Make Eloquent model attributes translatables using Translations table

Scrutinizer Code Quality Code Coverage Build Status StyleCI License: MIT Laravel 6.x

This package contains a trait to make Eloquent attributes translatable. Translations are stored in Translations database table.

Once the trait is installed on the model you can do these things:

$customer = new Customer; // An Eloquent model
$customer
   ->setTranslation('greeting', 'en', 'Hello')
   ->setTranslation('greeting', 'es', 'Hola')
   ->save();
   
$customer->greeting; // Returns 'Hello' given that the current app locale is 'en'
$customer->getTranslation('greeting', 'es'); // returns 'Hola'

app()->setLocale('es');

$customer->greeting; // Returns 'Hola'

Installation

You can install the package via composer:

composer require latevaweb/laravel-translatable

If you want to change the default model or the default tables names, you could publish the config file:

php artisan vendor:publish --provider="LaTevaWeb\Translatable\TranslatableServiceProvider" --tag=config --force

You must publish the migration file to create polymorphic and main translations tables:

php artisan vendor:publish --provider="LaTevaWeb\Translatable\TranslatableServiceProvider" --tag=migrations --force

Making a model translatable

The required steps to make a model translatable are:

  • First, you need to add the LaTevaWeb\Translatable\Traits\Translatable-trait.
  • Next, you should create a public static property $translatable which holds an array with all the names of attributes you wish to make translatable.
  • You have to create a field in the migration of your model type string and nullable.

Here's an example of a prepared model:

use Illuminate\Database\Eloquent\Model;
use LaTevaWeb\Translatable\Traits\Translatable;

class NewsItem extends Model
{
    use Translatable;
       
    protected $fillable = ['greeting'];
    public static $translatable = ['greeting'];
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-12-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固