Download the PHP package alexkramse/laravel-translatable-table without Composer
On this page you can find all versions of the php package alexkramse/laravel-translatable-table. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download alexkramse/laravel-translatable-table
More information about alexkramse/laravel-translatable-table
Files in alexkramse/laravel-translatable-table
Package laravel-translatable-table
Short Description Provides simple translation for model data via db
License MIT
Informations about the package laravel-translatable-table
Laravel Translatable Table
Laravel Translatable Table is a package designed to simplify handling translations stored in a separate table. It provides traits, casts, and utilities to manage and interact with translatable attributes seamlessly.
Supported Laravel Versions
The package supports Laravel 8, 9, and 10.
Installation
To install the package, use Composer:
Configuration
After installation, publish the configuration file:
This will create a config/table-translations.php file, where you can define supported locales and configure translation settings.
Usage
Setting Up a Translatable Model
- Use the
HasTranslatableTabletrait in your model. - Define the
translatableTableAttributesmethod to specify which attributes are translatable. - Ensure your model has a relationship to a translation model.
Example:
Creating a Translation Model
For each translatable model, you will need to create a corresponding translation model. For example, for the Article model, you will need to create a ArticleTranslation model like this:
This model should be associated with the article_translations table (or another name depending on your schema). It contains the translated fields and references the original model (in this case, Article).
Migration for Translations
You will also need to create a migration for the article_translations table. Here's an example migration:
Configuring Locales
Update the config/table-translations.php file to define the supported locales:
Interacting with Translations
You can manage translations directly via the i18n attribute on the translatable model:
Advanced Features
- Customizing Locales: You can dynamically define available locales via the configuration file.
- Eloquent Events: Translations are automatically handled during
createandupdateevents.
Notes
This is the first version of the package. The README and code may contain some inaccuracies or incomplete features. If you encounter any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request.
Testing
To test the package functionality, include your tests using Laravel's testing tools or Pest framework.
License
This package is open-sourced software licensed under the MIT license.