Download the PHP package kongulov/nova-tab-translatable without Composer
On this page you can find all versions of the php package kongulov/nova-tab-translatable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kongulov/nova-tab-translatable
More information about kongulov/nova-tab-translatable
Files in kongulov/nova-tab-translatable
Package nova-tab-translatable
Short Description Making Nova Tab Translatable
License MIT
Homepage https://github.com/kongulov/nova-tab-translatable
Informations about the package nova-tab-translatable
Making Laravel Nova Tab Translatable Nova 5 ready
This package contains a NovaTabTranslatable
class you can use to make any Nova field type translatable with tabs. Use the master branch for Nova 5 and the 1.x branch for Nova 4.
Imagine you have this fields
method in a Post Nova resource:
That Post Nova resource will be rendered like this.
Requirements
php: >=7.1.0
spatie/laravel-translatable: ^4.0
Installation
Install the package in a Laravel Nova project via Composer:
This is the contents of the file which will be published at config/tab-translatable.php
Usage
You must prepare your model as explained in the readme of laravel-translatable. In short: you must add json
columns to your model's table for each field you want to translate. Your model must use the Spatie\Translatable\HasTranslations
on your model. Finally, you must also add a $translatable
property on your model that holds an array with the translatable attribute names.
Now that your model is configured for translations, you can use NovaTabTranslatable
in the related Nova resource. Any fields you want to display in a multilingual way can be passed as an array to NovaTabTranslatable
.
If you want to make the field required only in certain languages, then you can use the required_lang
rule,
But if you want to make the field required in all languages, then use the laravel rules
-
Replace field name
-
If you want to save the tab in the last selected language, call the
saveLastSelectedLang()
method or in the config replace'save_last_selected_lang' => false
with'save_last_selected_lang' => true
- If on the index and detail pages you want to turn off the tab and show it each as a row, use trait
TranslatableTabToRowTrait
in your resource
Credits
License
This project is open-sourced software licensed under the MIT license.