ngiraud/nova-translatable-v2 问题修复 & 功能扩展

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

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

ngiraud/nova-translatable-v2

最新稳定版本:2.0.0

Composer 安装命令:

composer require ngiraud/nova-translatable-v2

包简介

A laravel-translatable extension for Laravel Nova. Inspired by optimistdigital/nova-translatable

README 文档

README

This Laravel Nova allows you to make any input field using the spatie/laravel-translatable package compatible and localisable.

This package is inspired by optimistdigital/nova-translatable.

Requirements

  • laravel/nova: ^3.0
  • spatie/laravel-translatable: ^4.0

You first need to set up the spatie/laravel-translatable package.

Installation

The package can be installed via composer:

composer require ngiraud/nova-translatable-v2

The package will automatically register the service provider.

You can publish the config file in order to use custom locales.

php artisan vendor:publish --tag="nova-translatable-config"

This is the contents of the published config file:

return [

    /**
     * the locales which the `translatable` wrapper will use by default.
     *
     * can be a:
     *  - keyed array (['en' => 'english])
     *  - callable that returns a keyed array
     */

    'locales' => ['en' => 'English'],

];

Usage

Simply call ->translatable() on a Nova field:

Text::make('Name')
  ->rules('required', 'min:2')
  ->translatable()

Optionally you can pass custom locales:

Number::make('Population')
  ->translatable([
    'en' => 'English',
    'et' => 'Estonian',
  ])

Validation

You can add validation rules for a single locale.

To do so, add the ->rulesFor() on your field and the HasTranslatable trait to your Nova resource:

class Product extends Resource
{
    use \NGiraud\NovaTranslatable\HasTranslatable;
    
    public function fields(Request $request)
    {
        return [
            ID::make()->sortable(),

            Text::make(__('Name'), 'name')
                ->sortable()
                ->translatable()
                ->rules(['max:255'])
                ->rulesFor('fr', [
                    'required',
                    'unique:products,sku->fr,{{resourceId}}'
                ])
    }
}

In this example, the rule max will be applied for name.* and the rule required will be applied for name.fr.

TODOS

  • Adding tests to the package

Changelog

Please see CHANGELOG for more information about recent changes.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email contact@ngiraud.me instead of using the issue tracker.

Credits

License

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

统计信息

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

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-02-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固