Download the PHP package labrodev/laravel-translatable without Composer
On this page you can find all versions of the php package labrodev/laravel-translatable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download labrodev/laravel-translatable
More information about labrodev/laravel-translatable
Files in labrodev/laravel-translatable
Package laravel-translatable
Short Description Laravel package providing a reusable trait for multilingual search in Eloquent JSON fields.
License MIT
Homepage https://github.com/labrodev/laravel-translatable
Informations about the package laravel-translatable
Labrodev Laravel Translatable
A Laravel package that adds JSON-based multilingual support to your Eloquent models. It provides:
- QueryFieldLocalizer: Utility to localize JSON fields to the current locale.
- SearchQueryBuilder: Trait for case-insensitive, multi-locale JSON field searching.
- LocaleResolver: Default resolver that returns
app.localeandapp.fallback_locale.
Installation
Require the package via Composer:
Optionally, publish the configuration (if you add a config file later):
Note: No configuration file is required out of the box—this is here for future customization.
Usage
1. Localizing JSON Fields
QueryFieldLocalizer helps you build locale-specific JSON paths for query fields:
2. Multilingual Search on JSON Columns
Add the SearchQueryBuilder trait to your Eloquent model:
Perform a case-insensitive search across all configured locales:
Or chain with existing conditions:
3. Customizing Locales
By default, locales come from app.locale and app.fallback_locale. To customize, bind your own LocaleResolver implementation:
Testing
This package uses Pest with Orchestra Testbench for testing and PHPStan for static analysis. This package uses Pest with Orchestra Testbench for testing and PHPStan for static analysis
-
Install dependencies:
-
Run static analysis:
- Run tests:
Tests cover:
QueryFieldLocalizer::translatableField()outputs correct JSON path.SearchQueryBuilderbuilds proper SQL & bindings for multilingual JSON searches.DefaultLocaleResolverTestresolve locales array.
Security
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
Contributing
Feel free to open issues or submit pull requests. Check Coding Standards:
- PSR-12
- Strict types enabled
License
MIT © Labro Dev
All versions of laravel-translatable with dependencies
illuminate/contracts Version ^10.0 || ^11.0 || ^12.0
spatie/laravel-package-tools Version ^1.92