PHP code example of parfumix / eloquent-translatable

1. Go to this page and download the library: Download parfumix/eloquent-translatable 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/ */

    

parfumix / eloquent-translatable example snippets




namespace App;

use Eloquent\Translatable\Translatable;
use Eloquent\Translatable\TranslatableTrait;
use Illuminate\Database\Eloquent\Model;

// Create page model .
class Page extends Model implements Translatable {

    use TranslatableTrait;
    
    // That attribute is not 


// Wil create and page and their translations
Page::create([
    'slug'    => 'title-slug',
    'en'       => [ 'title' => 'English title', 'description' => 'English description' ],
    'ru'       => [ 'title' => 'Russian title', 'description' => 'Russian description' ] 
]);

// Will access Page translation instance
Page::first()->translate('en') 

// will access translate title in english 
Page::first()->translate('en')->title

// Will check if page have translation in english
Page::first()->hasTranslation('en')

// Will delete english translation for current page 
Page::first()->removeTranslation('en')

// Will return all translation for current page instance 
Page::first()->translations


  $ php composer.phar