PHP code example of onurkacmaz / laravel-model-translate
1. Go to this page and download the library: Download onurkacmaz/laravel-model-translate 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/ */
onurkacmaz / laravel-model-translate example snippets
use Onurkacmaz\LaravelModelTranslate\Traits\Translatable;
class Blog extends Model
{
use Translatable;
// You can define which fields will be translated
public function getTranslatable(): array
{
return ['title', 'content'];
}
}
use Onurkacmaz\LaravelModelTranslate\Traits\Translatable;
class TestController extends Controller
{
public function index() {
$translate = new LaravelModelTranslate();
$translate->setColumns(['title', 'content']);
$translate->setModel($blog);
$translate->setLocale('en');
$translate->translate();
// or
$translate = new LaravelModelTranslate($blog, ['title', 'content'], 'en');
$translate->translate();
}
}
use Onurkacmaz\LaravelModelTranslate\Traits\Translatable;
class TestController extends Controller
{
public function index() {
$translate = LaravelModelTranslate::make()
->setModel($account)
->setLocale('en')
->setColumns(['title', 'content'])
->translate();
}
}