Download the PHP package rahmanramsi/laravel-translatable without Composer
On this page you can find all versions of the php package rahmanramsi/laravel-translatable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rahmanramsi/laravel-translatable
More information about rahmanramsi/laravel-translatable
Files in rahmanramsi/laravel-translatable
Package laravel-translatable
Short Description This is my package laravel-translatable
License MIT
Homepage https://github.com/rahmanramsi/laravel-translatable
Informations about the package laravel-translatable
Laravel-Translatable
Laravel Translatable is a package for easily attaching arbitrary translation data to Eloquent Models.
Features
- One-to-many polymorphic relationship allows attaching translated data to Eloquent models without needing to adjust the database schema.
Installation & Setup
You can install the package via composer:
You can publish and run the migrations with:
You can publish the config file with:
This is the contents of the published config file:
Making a model translatable
The required steps to make a model translatable are:
- First, you need to add the
RahmanRamsi\LaravelTranslatable\HasTranslationstrait. - Next, you should create a public property $translatable which holds an array with all the names of attributes you wish to make translatable.
Here's an example of a prepared model:
Basic Usage
Getting and setting translations
First, you must prepare your model as instructed in the installation instructions.
Setting a translation
Here's an example, given that name is a translatable attribute:
Changes automatically saved
To set a translation for a specific locale you can use this method:
You can set translations for multiple languages with
Getting a translation
The easiest way to get a translation for the current locale is to just get the property for the translated attribute. For example (given that name is a translatable attribute):
You can also use this method:
Getting all translations
You can get all translations by calling getTranslations() without an argument:
Or you can use the accessor:
The methods above will give you back an array that holds all translations, for example:
The method above returns, all locales. If you only want specific locales, pass that to the second argument of getTranslations.
Here's an example:
Get locales that a model has
You can get all locales that a model has by calling locales() without an argument:
Testing
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
- Rahman Ramsi
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-translatable with dependencies
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^10.0||^11.0||^12.0