承接 parfumix/eloquent-translatable 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

parfumix/eloquent-translatable

最新稳定版本:v1.1

Composer 安装命令:

composer require parfumix/eloquent-translatable

包简介

Eloquent translate

README 文档

README

##Introduction

Eloquent translatable allow you easy to translate your eloquent models in different languages. This package working strongly with https://github.com/parfumix/laravel-localization and install that package.

So before start working under eloquent translatable please study how to implement localization on your website.

Instalation

You can use the composer package manager to install. From console run:

  $ php composer.phar require parfumix/eloquent-translatable "v1.0"

or add to your composer.json file

"parfumix/eloquent-translatable": "v1.0"

##Basic usage

Before stary working with translatable package you have implement Translatable contract on your eloquent model and use TranslatableTrait .

<?php

namespace App;

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

// Create page model .
class Page extends Model implements Translatable {

    use TranslatableTrait;
    
    // That attribute is not required, will try to detect class name. If you have one custom you can do it.
    protected $translationClass = PageTranslations::class;

}

// Create translation model for page .
class PageTranslations extends Model {

    public $timestamps = false;
    
    protected $fillable = ['page_id', 'language_id', 'title', 'description'];

}

and create translation model for you eloquent model.

##How to use

// Wil create and page and their translations
Page::create([
    'slug'    => 'title-slug',
    'en'       => [ 'title' => 'English title', 'description' => 'English description' ],
    'ru'       => [ 'title' => 'Russian title', 'description' => 'Russian description' ] 
]);

// Will access Page translation instance
Page::first()->translate('en') 

// will access translate title in english 
Page::first()->translate('en')->title

// Will check if page have translation in english
Page::first()->hasTranslation('en')

// Will delete english translation for current page 
Page::first()->removeTranslation('en')

// Will return all translation for current page instance 
Page::first()->translations

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-09-23