https://github.com/kolirt/laravel-translations
https://github.com/kolirt/laravel-translations
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/kolirt/laravel-translations
- Owner: kolirt
- License: mit
- Created: 2019-05-24T05:55:00.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-07-27T14:17:30.000Z (almost 2 years ago)
- Last Synced: 2025-01-28T15:14:05.811Z (4 months ago)
- Language: PHP
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Laravel Translations
Package tested with Laravel 5.8. Other versions are not tested.| Laravel version | Tested |
| ---------------- | ------- |
| 5.8.* | ✅ |## Installation
```
$ composer require kolirt/laravel-translations
```
```
$ php artisan translations:install
```
Configure translations config on config/translations.php path.
##### If you use sql count method or eloquent count method you need disabling global scope 'translatable'
```php
withoutGlobalScope('translatable');
```
## Important
If you use **where** method with translatable fields then you will see that it isn't working. You have to use **having** method.## Usage
You need use Kolirt\Translations\Traits\Translatable trait to you model and fill $translatable property. You can set the type of the column. The default type is a string.
```php
'text'];
}
```### Availables column types
```
string
text
mediumText
longText
smallInteger
tinyInteger
integer
mediumInteger
bigInteger
decimal
boolean
date
dateTime
timestamp
```### Return current language translation by column name
```php
name;// OR
$tag = Tag::first();
$tag->translation('name');
```### Return translations by column name
```php
translations('name');
```### Save translations
You can't use next example code, because it don't work for saving translations.
```php
name = 1;
$tag->save();
```You need use update method for saving translations.
```php
update([
'name' => [
'uk' => 'uk label',
'en' => 'en label'
]
]);
```### Validate
```php
validate([
'name.*' => [
'unique_loc:table,type,name,id' // id not required
],
]);/*
'name.*' must have array of language translates. Example:
'name' => [
'uk' => 'uk label'
'en' => 'en label'
]
*/
```### Local scope
You can disable globalScope in config and use local scope.
```php
first();
```