*/ use HasFactory; use HasModelNaming; use HasTranslations; use SoftDeletes; /** * The attributes that are mass assignable. * * @var list */ protected $fillable = [ 'name', 'url_re7', 'url_prod', 'project_manager_id', 'gitlab_project_id', ]; /** * The translatable columns. * * @var list */ public $translatable = [ 'name', ]; /** * Relations should be included in the cache. * * @var list */ protected static $cacheRelations = [ 'projectManager', 'gitlabProject', ]; /** * Perform any actions required after the model boots. * * @return void */ #[\Override] protected static function booted(): void { $assertUrls = function (self $model) { if ($model->url_re7) { ToolboxHelper::assertNoInternalUrls('url_re7', $model->url_re7); } if ($model->url_prod) { ToolboxHelper::assertNoInternalUrls('url_prod', $model->url_prod); } }; static::creating($assertUrls); static::updating($assertUrls); } // * RELATIONS. /** * Get users associated to the site. * * @return \Illuminate\Database\Eloquent\Relations\MorphToMany<\App\Models\User> */ public function users(): \Illuminate\Database\Eloquent\Relations\MorphToMany { return $this->morphedByMany( User::class, 'sitable', 'sitables', 'site_id', 'sitable_id' )->withPivot('created_at'); } /** * Get project manager of the site. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo<\App\Models\User,\App\Models\Site> */ public function projectManager(): \Illuminate\Database\Eloquent\Relations\BelongsTo { return $this->belongsTo(User::class, 'project_manager_id'); } /** * Get project manager of the site. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo<\App\Models\GitlabProject,\App\Models\Site> */ public function gitlabProject(): \Illuminate\Database\Eloquent\Relations\BelongsTo { return $this->belongsTo(GitlabProject::class, 'gitlab_project_id'); } }