*/ use HasFactory; use HasModelNaming; use HasTranslations; use SoftDeletes; /** * The attributes that are mass assignable. * * @var list */ #[\Override] protected $fillable = [ 'name', 'url_re7', 'url_prod', 'project_manager_id', 'gitlab_project_id', ]; /** * The translatable columns. * * @var list */ public $translatable = [ 'name', ]; /** * Perform any actions required after the model boots. * * @return void */ #[\Override] protected static function booted(): void { $assertUrls = function (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); } }; static::creating($assertUrls); static::updating($assertUrls); } /** * Get relations to include in the cache. * * @return list */ public static function getCacheRelations(): array { return ['projectManager', 'gitlabProject', 'users']; } // * RELATIONS. /** * Get users associated to the site. * * @return \Illuminate\Database\Eloquent\Relations\MorphToMany<\App\Models\User,$this,\Illuminate\Database\Eloquent\Relations\MorphPivot,'pivot'> */ public function users(): \Illuminate\Database\Eloquent\Relations\MorphToMany { return $this->morphedByMany( User::class, 'sitable', 'sitables', 'site_id', 'sitable_id', )->withPivot('created_at'); } /** * Get brands associated to the site. * * @return \Illuminate\Database\Eloquent\Relations\MorphToMany<\App\Models\Brand,$this,\Illuminate\Database\Eloquent\Relations\MorphPivot,'pivot'> */ public function brands(): \Illuminate\Database\Eloquent\Relations\MorphToMany { return $this->morphedByMany( Brand::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,$this> */ 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,$this> */ public function gitlabProject(): \Illuminate\Database\Eloquent\Relations\BelongsTo { return $this->belongsTo(GitlabProject::class, 'gitlab_project_id'); } }