定制 said/private-package 二次开发

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

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

said/private-package

Composer 安装命令:

composer require said/private-package

包简介

This is a Laravel package containing a trait for translatable Eloquent models. This package follows the approach to have only a single table to maintain all the translations.

README 文档

README

This is a Laravel package containing a trait for translatable Eloquent models. This package follows the approach to have only a single table to maintain all the translations.

This approach may not be perfect for every use case as the table can grow really big. But compared to all the other packages this approach is the most flexible as it lets you make models and its attributes translatable without extra configuration.

Alternatives to this package are following packages:

  1. Spatie/laravel-translatable saves the translatable attributes as jsons
  2. dimsav/laravel-translatable expects a new table for every new model that has translatable attributes

Requirements

This package require a minimum Laravel version of 5.8 and PHP in version 7.1

Installation

You can install the package via composer:

composer require said/laravel-translatable

Now you can use this Trait on any Eloquent Model of your project.

Usage

To make your Eloquent Model translatable just add the Said\Translatable\Traits\TranslatableTrait to your model. Then add a public attribute$translatable_columns` as an array containing all the attributes that should be translatable.

<?php

namespace App;

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

class MyModel extends Model
{
    use Translatable;
    protected $translatable_columns=[
        'name'
    ];
    protected $fillable=[
        'price'
    ];
}

Methods

The simplest version of getting an translation is to simply get the property. This will return the value of the property in the current language

// assuming $myModel is an instace of MyModel class defined above
// and the translations are set
echo $myModel->name; // returns 'Product'
App::setLocale('fr');
echo $myModel->name; // returns 'Produit'

You can also use

$myModel->in('fr')->translate('name'); // returns 'Produit'

Getting the translated model

soon

Translating an Model

You can translate a model using ... soon Changelog

Check CHANGELOG for the changelog

Testing

soon

Contributing

soon

Security

soon

About Said Ibrahim

soon.

License

The MIT License (MIT).

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-04-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固