PHP code example of syscape-space / laravel-translation
1. Go to this page and download the library: Download syscape-space/laravel-translation 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/ */
syscape-space / laravel-translation example snippets
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use SyscapeSpace\LaravelTranslation\Traits\hasTranslation;
class Post extends Model
{
use HasFactory, HasTranslation;
// to force laravel accept the translation attributes
protected $guarded = [];
#or if you have time
protected $fillable = ['title','title_en','title_ar','content','content_en','content_ar'];
//-------------------------------------------------
// just like that without any migration or configuration
public $translationAttributes = [
'title',
'content',
];
}
#any where in your code
// depending on the current locale
$post = Post::create([
'title' => 'title',
'body' => 'content',
]);
#or
$post = Post::create([
'title_ar' => 'عنوان',
'title_en' => 'title',
'body_ar' => 'محتوى',
'body_en' => 'content',
]);
# and
$post->title; // title
#or
$post->title_ar; // عنوان
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.