PHP code example of roi-up-agency / laravel-translatable
1. Go to this page and download the library: Download roi-up-agency/laravel-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/ */
roi-up-agency / laravel-translatable example snippets
$newsItem = new NewsItem; // This is an Eloquent model
$newsItem
->setTranslation('name', 'en', 'Name in English')
->setTranslation('name', 'nl', 'Naam in het Nederlands')
->save();
$newsItem->name; // Returns 'Name in English' given that the current app locale is 'en'
$newsItem->getTranslation('name', 'nl'); // returns 'Naam in het Nederlands'
app()->setLocale('nl');
$newsItem->name; // Returns 'Naam in het Nederlands'
return [
'fallback_locale' => 'en',
];
$newsItem->name;
public function getTranslation(string $attributeName, string $locale) : string
$newsItem->getTranslations();
$yourModel->translations
$newsItem->name = 'New translation';
$newsItem->setTranslation('name', 'en', 'Updated name in English');
$newsItem->save();
/** @var \Illuminate\Database\Eloquent\Model */
public $model;
/** @var string */
public $attributeName;
/** @var string */
public $locale;
public $oldValue;
public $newValue;
NewsItem::create([
'name' => [
'en' => 'Name in English',
'nl' => 'Naam in het Nederlands'
],
]);
NewsItem::where('name->en', 'Name in English')->get();