Download the PHP package fevrok/laravel-translatable without Composer
On this page you can find all versions of the php package fevrok/laravel-translatable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download fevrok/laravel-translatable
More information about fevrok/laravel-translatable
Files in fevrok/laravel-translatable
Package laravel-translatable
Short Description This package allows you to translate your models fields.
License MIT
Homepage https://github.com/fevrok/laravel-translatable
Informations about the package laravel-translatable
Laravel Translatable
It's a Laravel model columns translation manager
How it works?
Installation
You can install the package via composer:
If you have Laravel 5.5 and up The package will automatically register itself.
else you have to add the service provider to config/app.php
publish config file and migration.
next migrate translations table
Setup
After finishing the installation you can open config/translatable.php
:
And update your config accordingly.
Making a model translatable
The required steps to make a model translatable are:
- use the
Fevrok\Translatable\Translatable
trait. - define the model translatable fields in
$translatable
property.
Here's an example of a prepared model:
Custom translations model
To get started, publish the assets again this will create new migration update table name to your desire.
CustomTranslation.php
Add $translations_model
property and give it to the model you wanna customize,
Usage
Eager-load translations
Get default language value
Get translated value
If you do not define locale, the current application locale will be used. You can pass in your own locale as a string. If you do not define fallbackLocale, the current application fallback locale will be used. You can pass your own locale as a string. If you want to turn the fallback locale off, pass false. If no values are found for the model for a specific attribute, either for the locale or the fallback, it will set that attribute to null.
Translate the whole model
If you do not define locale, the current application locale will be used. You can pass in your own locale as a string. If you do not define fallbackLocale, the current application fallback locale will be used. You can pass in your own locale as a string. If you want to turn the fallback locale off, pass false. If no values are found for the model for a specific attribute, either for the locale or the fallback, it will set that attribute to null.
Check if model is translatable
Set attribute translations
This will update or create the translation for title of the post with the locale da. Please note that if a modified attribute is not translatable, then it will make the changes directly to the model itself. Meaning that it will overwrite the attribute in the language set as default.
Query translatable Models
To search for a translated value, you can use the whereTranslation
method.
For example, to search for the slug of a post, you'd use
whereTranslation
accepts the following parameter:
field
the field you want to search inoperator
the operator. Defaults to=
. Also can be the value (Same as where)value
the value you want to search forlocales
the locales you want to search in as an array. Leave asnull
if you want to search all localesdefault
also search in the default value/locale. Defaults to true.
Maintainers
Abdellah Chadidi |