ldc-supportweb/app/Models/GitlabLabel.php
2026-05-26 12:15:12 +02:00

74 lines
2.1 KiB
PHP

<?php
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 integer $id Primary key of the gitlab label.
* @property string $name Name of the gitlab label.
* @property integer $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>
*/
protected $fillable = [
'name',
'gitlab_id',
];
/**
* The translatable columns.
*
* @var list<string>
*/
public $translatable = [
'name',
];
/**
* Perform any actions required after the model boots.
*
* @return void
*/
protected static function booted(): void
{
static::creating(function (self $model) {
self::manageFields($model);
});
static::updating(function (self $model) {
self::manageFields($model);
});
}
// * METHODS.
/**
* Manage model fields.
*
* @param self $model
* @return void
*/
private static function manageFields(self $model): void
{
TranslationHelper::assertTranslationFieldIsUnique($model, $model->name, 'name');
TranslationHelper::validateFallbackTranslations($model);
}
}