Languages
表包含:
id*
Translations
表包含:
language_id* | language | country | translate_code_id*
Locales
表包含:
id* | code | name
(*是主键)
name
(=语言)和country
作为属性?我成功为name
创建了一个getter,但它看起来并不像#34;"去做吧。
这是我的模特:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Language extends Model {
protected $table = 'languages';
protected $primaryKey = 'id';
function translations() {
return $this->hasMany(LanguageTranslation::class, 'language_id');
}
function locale() {
$locale = Locale::where('code', config('app.locale'))->first();
return $this->translations()->where('translate_code_id', $locale->id);
}
function getName() {
if ($locale = $this->locale->first())
return $this->locale->first()->toArray()['language'];
}
}