定制 syscape-space/laravel-translation 二次开发

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

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

syscape-space/laravel-translation

最新稳定版本:v0.0.4

Composer 安装命令:

composer require syscape-space/laravel-translation

包简介

A Laravel package for model attributes translations

README 文档

README

Latest Version on Packagist Total Downloads GitHub Actions

A Laravel package for model attributes translations

Installation

You can install the package via composer:

  1. composer require syscape-space/laravel-translation
  2. publish the migration to create the media table by running php artisan vendor:publish --provider="SyscapeSpace\LaravelTranslation\LaravelTranslationServiceProvider" --tag="migrations".

Usage

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use SyscapeSpace\LaravelTranslation\Traits\hasTranslation;

class Post extends Model
{
    use HasFactory, HasTranslation;
    // to force laravel accept the translation attributes
    protected $guarded = [];
    #or if you have time
    protected $fillable = ['title','title_en','title_ar','content','content_en','content_ar'];
    //-------------------------------------------------
    // just like that without any migration or configuration
    public $translationAttributes = [
        'title',
        'content',
    ];

}
#any where in your code
// depending on the current locale
$post = Post::create([
'title' => 'title',
'body' => 'content',
]);
#or
$post = Post::create([
'title_ar' => 'عنوان',
'title_en' => 'title',
'body_ar' => 'محتوى',
'body_en' => 'content',
]);
# and 
$post->title; // title 
#or 
$post->title_ar; // عنوان

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email ahmedalmory02@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-09-17