Download the PHP package unusualdope/filament-model-translatable without Composer
On this page you can find all versions of the php package unusualdope/filament-model-translatable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package filament-model-translatable
Filament-Model-Translatable (plugin)
DESCRIPTION
Adds the ability to insert translations in content using a language table. For example, you can create a main model that stores the object id and the data that is not translatable, on the lang model you have to define the foreign key for the main object(in this case post_id) and the one for the language that has always to be "language_id". Below an example of model definition in YAML for blueprint package:
INSTALLATION
Simply install using composer
run then
and follow the prompts to publish and run the migrations and create the languages.
don't forget to register the plugin in your panel
HOW TO USE IT
MAIN MODEL
In the main model use the provided trait "HasTranslation":
The plugin assumes that the translatable model is named as the main model + "Language" and the foreign key is the main model name in CamelCase + "Language" (e.g. PostLanguage)
if you want to change the language model name you can do so overwriting the property in your main model
the plugin assumes that the foreign key is the standard laravel foreign key (eg: post_id), if you want to change it you can do so overwriting the property in your main model
if for any reason you want to stop/pause the translat-ability of your model you can set the property $is_translatable to false
On the main model you have to define the fields that will be translatable using standard Filament fields
as you would do in a resource, specify them in method setTranslatableFilamentFields(), the make() method
has to contain the field names that are present in the database on the
RESOURCE
In the RESOURCE when defining the form insert the translatable fields where you want by using the method addTranslatableFieldsToSchema() and passing as parameter the field name exactly as defined in the database and in the main model
CREATE AND EDIT RESOURCE PAGES
On the CREATE page extend
instead of the standard
Filament\Resources\Pages\CreateRecord
On the EDIT page extend
instead of the standard Filament\Resources\Pages\EditRecord
RESULT
You will get a tab that let you change language and fill the content for every language:
DATA RETRIEVAL
The trait HasTranslation provides a method to retrieve the translated data for the current language by using the defined HasOne relationship "currentLanguage", if you want to retrieve the post name in the current language in frontend you can do so by using the following code:
if you need to access all the data for all the languages you can use the HasMany relationship "languageData", you can do so by using the following code:
ISSUES OR SUGGESTIONS
Please feel free to give any suggestions for improvements or report any issue directly on the gitHub plugin repository
All versions of filament-model-translatable with dependencies
daftspunk/laravel-config-writer Version *
guzzlehttp/guzzle Version ^7.2
filament/filament Version ^3.1
laravel/framework Version >=10.0