<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
esign / laravel-helpermodel-translatable example snippets
return [
/**
* These are the default namespaces where the HelperModelTranslatable
* looks for the helper models. You may pass in either a string
* or an array, they are tried in order and the first match is used.
*/
'model_namespaces' => ['App', 'App\\Models'],
];
use Esign\HelperModelTranslatable\HelperModelTranslatable;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
use HelperModelTranslatable;
public $translatable = ['title'];
}
use Illuminate\Database\Eloquent\Model;
class PostTranslation extends Model
{
...
}
use Esign\HelperModelTranslatable\HelperModelTranslatable;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
use HelperModelTranslatable;
public $translatable = ['title'];
public function getFallbackLocale(?string $locale = null): ?string
{
return 'fr';
}
}
use Esign\HelperModelTranslatable\HelperModelTranslatable;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
use HelperModelTranslatable;
public $translatable = ['title'];
protected function getHelperModelClass(): string
{
return CustomPostTranslation::class;
}
protected function getHelperModelForeignKey(): string
{
return 'custom_post_id';
}
}
use Esign\HelperModelTranslatable\HelperModelTranslatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Post extends Model
{
use HelperModelTranslatable;
public $translatable = ['title'];
public function translations(): HasMany
{
return $this->hasMany(PostTranslation::class);
}
}
use Esign\HelperModelTranslatable\HelperModelTranslatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Post extends Model
{
use HelperModelTranslatable;
protected $helperModelRelation = 'otherTranslations';
public $translatable = ['title'];
}