PHP code example of astrotomic / laravel-translatable
1. Go to this page and download the library: Download astrotomic/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/ */
astrotomic / laravel-translatable example snippets
$post = Post::first();
echo $post->translate('en')->title; // My first post
App::setLocale('en');
echo $post->title; // My first post
App::setLocale('de');
echo $post->title; // Mein erster Post
$post = Post::first();
echo $post->translate('en')->title; // My first post
$post->translate('en')->title = 'My cool post';
$post->save();
$post = Post::first();
echo $post->translate('en')->title; // My cool post
$data = [
'author' => 'Gummibeer',
'en' => ['title' => 'My first post'],
'fr' => ['title' => 'Mon premier post'],
];
$post = Post::create($data);
echo $post->translate('fr')->title; // Mon premier post
'translations_wrapper' => 'translations',
$data = [
'author' => 'Gummibeer',
'translations' => [
'en' => ['title' => 'My first post'],
'fr' => ['title' => 'Mon premier post'],
],
];
$post = Post::create($data);
echo $post->translate('fr')->title; // Mon premier post
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.