ldc-supportweb/app/Models/GitlabProject.php
2026-06-05 12:03:50 +02:00

92 lines
2.6 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Uwil\LaravelActivityLogs\Traits\HasActivityLog;
use Uwil\LaravelBackend\Traits\Models\HasCache;
use Uwil\LaravelI18n\Helpers\TranslationHelper;
use Uwil\LaravelI18n\Interfaces\TranslatableModel;
use Uwil\LaravelI18n\Traits\Models\HasTranslations;
/**
* @property integer $id Primary key of the gitlab project.
* @property string $name Name of the gitlab project.
* @property string $url Url of the gitlab project.
* @property string $is_archived Archived status of the gitlab project.
* @property integer $gitlab_id Gitlab id of the gitlab project.
* @property-read \Illuminate\Support\Carbon $created_at Date the gitlab project was created.
* @property-read \Illuminate\Support\Carbon $updated_at Date the gitlab project was updated.
* @property-read \Illuminate\Support\Carbon $deleted_at Date the gitlab project was deleted.
*/
class GitlabProject extends Model implements TranslatableModel
{
use HasActivityLog;
use HasCache;
/** @use \Illuminate\Database\Eloquent\Factories\HasFactory<\Database\Factories\GitlabProjectFactory> */
use HasFactory;
use HasTranslations;
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
#[\Override]
protected $fillable = [
'name',
'url',
'is_archived',
'gitlab_id',
];
/**
* The translatable columns.
*
* @var list<string>
*/
public $translatable = [
'name',
];
/**
* The attributes that should be cast.
*
* @var array<string,string>
*/
#[\Override]
protected $casts = [
'is_archived' => 'boolean',
];
/**
* Perform any actions required after the model boots.
*
* @return void
*/
#[\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.
*
* @param self $model
* @return void
*/
private static function manageFields(self $model): void
{
TranslationHelper::assertTranslationFieldIsUnique($model, $model->name, 'name');
TranslationHelper::validateFallbackTranslations($model);
}
}