ldc-supportweb/app/Models/GitlabLabel.php
2026-06-05 17:05:46 +02:00

75 lines
2 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Uwil\LaravelActivityLogs\Traits\HasActivityLog;
use Uwil\LaravelI18n\Helpers\TranslationHelper;
use Uwil\LaravelI18n\Interfaces\TranslatableModel;
use Uwil\LaravelI18n\Traits\Models\HasTranslations;
/**
* @property int $id Primary key of the gitlab label.
* @property string $name Name of the gitlab label.
* @property int $gitlab_id Gitlab id of the gitlab label.
* @property-read \Illuminate\Support\Carbon $created_at Date the gitlab label was created.
* @property-read \Illuminate\Support\Carbon $updated_at Date the gitlab label was updated.
* @property-read \Illuminate\Support\Carbon $deleted_at Date the gitlab label was deleted.
*/
class GitlabLabel extends Model implements TranslatableModel
{
use HasActivityLog;
/** @use \Illuminate\Database\Eloquent\Factories\HasFactory<\Database\Factories\GitlabLabelFactory> */
use HasFactory;
use HasTranslations;
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
#[\Override]
protected $fillable = [
'name',
'gitlab_id',
];
/**
* The translatable columns.
*
* @var list<string>
*/
public $translatable = [
'name',
];
/**
* Perform any actions required after the model boots.
*/
#[\Override]
protected static function booted(): void
{
static::creating(function (self $model): void {
self::manageFields($model);
});
static::updating(function (self $model): void {
self::manageFields($model);
});
}
// * METHODS.
/**
* Manage model fields.
*/
private static function manageFields(self $model): void
{
TranslationHelper::assertTranslationFieldIsUnique($model, $model->name, 'name');
TranslationHelper::validateFallbackTranslations($model);
}
}