*/ protected $fillable = [ 'name', 'url_re7', 'url_prod', 'gitlab_project_id', 'project_manager_id' ]; /** * The accessors to append to the model's array form. * * @var list */ protected $appends = [ 'value' ]; // * EVENTS /** * 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 /** * Common methods function. * * @param self $model * @return void */ private static function manageFields(self $model): void { if ($model->url_re7) { ToolboxHelper::assertNoInternalUrls('url_re7', $model->url_re7); } if ($model->url_prod) { ToolboxHelper::assertNoInternalUrls('url_prod', $model->url_prod); } } // * RELATIONSHIPS /** * HasMany Message relation * The users of type client that would have access to this site tickets. * * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ public function users(): \Illuminate\Database\Eloquent\Relations\BelongsToMany { return $this->belongsToMany(User::class); } /** * HasMany Ticket relation. * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function tickets(): \Illuminate\Database\Eloquent\Relations\HasMany { return $this->hasMany(Ticket::class, 'site_id'); } /** * BelongsTo Brand relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function brand(): \Illuminate\Database\Eloquent\Relations\BelongsTo { return $this->belongsTo(Brand::class); } /** * BelongsTo User relation * The project manager of the site * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function projectManager(): BelongsTo { return $this->belongsTo(User::class, 'project_manager_id'); } /** * BelongsTo Project relation * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function project(): \Illuminate\Database\Eloquent\Relations\BelongsTo { return $this->belongsTo(Project::class); } /** * Return value attribute for belongsto search component. * * @return \Illuminate\Database\Eloquent\Casts\Attribute */ protected function value(): \Illuminate\Database\Eloquent\Casts\Attribute { return new Attribute( get: fn() => $this->id, ); } }