PHP code example of despark / laravel-db-localization
1. Go to this page and download the library: Download despark/laravel-db-localization 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/ */
despark / laravel-db-localization example snippets
use Despark\LaravelDbLocalization\i18nModelTrait;
class Contacts extends Eloquent
{
use i18nModelTrait; // You must use i18nModelTrait
protected $fillable = [
'fax',
'phone',
];
protected $translator = 'Despark\LaravelDbLocalization\ContactsI18n'; // Here you need to add your translations table model name
protected $translatorField = 'contact_id'; // your translator field name
protected $localeField = 'i18n_id'; // here is your locale field name
protected $translatedAttributes = ['contact_id', 'i18n_id', 'name', 'location']; // translatable fillables
}
class ContactsI18n extends Eloquent
{
protected $table = 'contacts_i18n';
}
// locale string
$contacts->translate('en'); // all fields
$contacts->translate('en')->location; // specific field
// locale id
$i18nId = 2;
$contacts->translate($i18nId); // all fields
$contacts->translate($i18nId)->location; // specific field
config/laravel-db-localization.php
'locale_class' => 'Despark\LaravelDbLocalization\I18n', // Eloquent model that handles your languages.
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.