kaantanis / filament-model-translatable
This is my package filament-model-translatable
Fund package maintenance!
KaanTanis
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-12-19 07:37:04 UTC
README
Filament model translatable is a package that provides a trait to make your models translatable in Laravel Filament. The data is stored in a new table with the model's id, the field name, the language, and the value.
Installation
You can install the package via composer:
composer require kaantanis/filament-model-translatable
You can publish and run the migrations with:
php artisan vendor:publish --tag="filament-model-translatable-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --tag="filament-model-translatable-config"
This is the contents of the published config file:
<?php return [ // except default locale on your app.php 'supported_locales' => [ 'tr', 'de', ], 'cache_time' => 10, // in minutes ];
Usage
// 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
Important Notice
When using the translatable
method, the ->translatable()
method must be called the last. Otherwise, other methods will not work.
When using Select component, be sure to use the ->options()
method after the ->translatable()
method.
// 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()
We need new ideas for version 2.0.0. Please open a discussion for your ideas.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.