kaantanis / filament-model-translatable
这是我创建的包 filament-model-translatable
v0.1.0-alpha
2024-08-15 08:06 UTC
Requires
- php: ^8.2
- illuminate/contracts: ^10.0||^11.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-arch: ^2.7
- pestphp/pest-plugin-laravel: ^2.3
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
This package is auto-updated.
Last update: 2024-09-19 07:11:20 UTC
README
filament-model-translatable 是一个提供特质的包,使得您在 Laravel Filament 中的模型可翻译。数据存储在包含模型 ID、字段名称、语言和值的新的表中。
安装
您可以通过 composer 安装此包
composer require kaantanis/filament-model-translatable
您可以使用以下命令发布和运行迁移
php artisan vendor:publish --tag="filament-model-translatable-migrations"
php artisan migrate
您可以使用以下命令发布配置文件
php artisan vendor:publish --tag="filament-model-translatable-config"
这是已发布配置文件的内容
<?php return [ // except default locale on your app.php 'supported_locales' => [ 'tr', 'de', ], 'cache_time' => 10, // in minutes ];
使用方法
// model use KaanTanis\FilamentModelTranslatable\Traits\ModelTranslatable; class Post extends Model { use ModelTranslatable; protected $translatable = [ 'title', 'body', ]; }
// Resource TextInput::make('title') ->translatable() // It works magically via macro
// Get the value $model->title // It will return the value of the app()->getLocale() $model->getTranslation('title', 'tr') // It will return the value of the target locale // if the given locale does not exist from database, it will return the title of the model itself
重要通知
当使用 translatable
方法时,必须在最后调用 ->translatable()
方法。否则,其他方法将无法正常工作。
当使用 Select 组件时,请确保在 ->translatable()
方法之后使用 ->options()
方法。
// This will all work TextInput::make('title') ->required() ->translatable() // This will only main component field required but other cloned translatable components will not be require // But still translatable TextInput::make('title') ->translatable() ->required()
我们需要为 2.0.0 版本提出新想法。请为您的想法发起讨论。
测试
composer test
更新日志
请参阅 CHANGELOG 了解最近更改的详细信息。
贡献
请参阅 CONTRIBUTING 了解详细信息。
安全漏洞
请参阅 我们的安全策略 了解如何报告安全漏洞。
鸣谢
许可证
MIT 许可证 (MIT)。请参阅 许可证文件 了解更多信息。