An open API service indexing awesome lists of open source software.

https://github.com/kolirt/laravel-translations


https://github.com/kolirt/laravel-translations

Last synced: 2 months ago
JSON representation

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();
```