Added the ability to dynamically translate on the project website.
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\Lang;
|
||||
use App\Models\Scopes\SortScope;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
@@ -33,6 +35,8 @@ final class ProjectLanguage extends Model
|
||||
'code',
|
||||
'is_default',
|
||||
'sort',
|
||||
'system_lang',
|
||||
'iso_code',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -43,8 +47,27 @@ final class ProjectLanguage extends Model
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'is_default' => 'boolean',
|
||||
'sort' => 'integer',
|
||||
'is_default' => 'boolean',
|
||||
'sort' => 'integer',
|
||||
'system_lang' => Lang::class,
|
||||
];
|
||||
}
|
||||
|
||||
protected function attributeLang(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: function () {
|
||||
|
||||
if ($this->iso_code) {
|
||||
return $this->iso_code;
|
||||
}
|
||||
|
||||
if ($this->system_lang) {
|
||||
return $this->system_lang->getLocale();
|
||||
}
|
||||
|
||||
return $this->code;
|
||||
},
|
||||
)->shouldCache();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user