62 lines
1.4 KiB
PHP
62 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Localization;
|
|
|
|
use App\Support\RelationValuesTrait;
|
|
use App\Support\UuidScopeTrait;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Support\Facades\App;
|
|
|
|
class Locale extends Model {
|
|
use UuidScopeTrait, SoftDeletes, RelationValuesTrait;
|
|
|
|
protected $dates = [
|
|
];
|
|
|
|
protected $fillable = [
|
|
'uuid',
|
|
'name',
|
|
'name_iso',
|
|
'title',
|
|
'is_enabled',
|
|
'is_default'
|
|
];
|
|
|
|
protected $hidden = [
|
|
'id'
|
|
];
|
|
|
|
|
|
public function scopeEnabled($query) {
|
|
return $query->where(['is_enabled' => true]);
|
|
}
|
|
|
|
|
|
public function getIsActiveAttribute(): bool {
|
|
return $this->name === App::getLocale();
|
|
}
|
|
|
|
|
|
public function toggle(): bool {
|
|
return $this->is_enabled ? $this->disable() : $this->enable();
|
|
}
|
|
public function enable(): bool {
|
|
return $this->update(['is_enabled' => true]);
|
|
}
|
|
public function disable(): bool {
|
|
return $this->update(['is_enabled' => false]);
|
|
}
|
|
|
|
|
|
public function setAsDefault(): bool {
|
|
self::query()->where(['is_default' => true])->update(['is_default' => false]);
|
|
return $this->update(['is_default' => true]);
|
|
}
|
|
|
|
public static function default() {
|
|
return self::query()->where(['is_default' => 1])->first();
|
|
}
|
|
|
|
}
|