*/ use HasFactory; use HasModelNaming; use HasTranslations; use SoftDeletes; /** * The attributes that are mass assignable. * * @var list */ #[\Override] protected $fillable = [ 'name', ]; /** * The translatable columns. * * @var list */ public $translatable = [ 'name', ]; /** * Perform any actions required after the model boots. */ #[\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. /** * Get relations to include in the cache. * * @return list */ public static function getCacheRelations(): array { return ['sites']; } /** * Manage model fields. */ private static function manageFields(self $model): void { TranslationHelper::assertTranslationFieldIsUnique($model, $model->name, 'name'); } // * RELATIONS. /** * Get sites associated to the brand. * * @return \Illuminate\Database\Eloquent\Relations\MorphToMany<\App\Models\Site,$this,\Illuminate\Database\Eloquent\Relations\MorphPivot,'pivot'> */ public function sites(): MorphToMany { return $this->morphToMany( Site::class, 'sitable', 'sitables', 'sitable_id', 'site_id', )->withPivot('created_at'); } }