*/ use HasFactory; /** * @var array */ public $fillable = ['name', 'fee_id']; public function getAmount(): int { return $this->children->sum('amount'); } /** * @return BelongsTo */ public function fee(): BelongsTo { return $this->belongsTo(Fee::class); } /** * @return HasMany */ public function children(): HasMany { return $this->hasMany(SubscriptionChild::class, 'parent_id'); } public static function booted(): void { static::deleting(fn ($model) => $model->children()->delete()); } /** * @return array */ public static function forSelect(): array { return static::select('name', 'id')->get()->toArray(); } }