PHP code example of escapework / laravel-translations
1. Go to this page and download the library: Download escapework/laravel-translations library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
escapework / laravel-translations example snippets
use EscapeWork\Translations\Translatable;
...
class Product extends Model
{
use Translatable;
}
// $data can have as many fields you want
$data = [
'title' => 'My translated title',
'description' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit',
];
$product->storeTranslation((array) $data, 'pt-br');
class Product extends Model
{
...
public function getTitleAttribute()
{
return $this->translations->_get('title');
}
...
}
// then, just call like a simple field
echo $product->title;