74 lines
1.6 KiB
PHP
74 lines
1.6 KiB
PHP
<?php declare(strict_types=1);
|
|
|
|
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;
|
|
use Illuminate\Database\Eloquent\Attributes\ScopedBy;
|
|
|
|
#[ScopedBy([SortScope::class])]
|
|
final class ProjectLanguage extends Model
|
|
{
|
|
use HasFactory, SoftDeletes;
|
|
|
|
/**
|
|
* The model's default values for attributes.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $attributes = [
|
|
'is_default' => false,
|
|
'sort' => 100,
|
|
];
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'title',
|
|
'code',
|
|
'is_default',
|
|
'sort',
|
|
'system_lang',
|
|
'iso_code',
|
|
];
|
|
|
|
/**
|
|
* Get the attributes that should be cast.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'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();
|
|
}
|
|
}
|