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


    EscapeWork\Translations\TranslationServiceProvider::class

EscapeWork\Translations\Locale::create(['id' => 'pt-br', 'title' => 'Português (Brasil)']);
EscapeWork\Translations\Locale::create(['id' => 'en',    'title' => 'English']);

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');

$product = Product::find(1);

foreach ((array) $request->translations as $locale => $data) {
    $product->storeTranslation((array) $data, $locale);
}

$product->deleteTranslations();

$product = Product::find(1);
echo $product->translations->_get('title'); // this will get the translation for the current config('app.locale') value

$product = Product::find(1);
echo $product->translations->_get('title', 'pt-br');

class Product extends Model
{
    ...
    public function getTitleAttribute()
    {
        return $this->translations->_get('title');
    }
    ...
}

// then, just call like a simple field
echo $product->title;
bash
$ php artisan vendor:publish --provider="EscapeWork\Translations\TranslationServiceProvider"
$ php artisan migrate