*/ protected $fillable = [ 'name', ]; /** * Validate that the maximum number of category approaches has not been exceeded. * * @throws \Exception If the maximum number of categories has been exceeded. */ protected function validateMaxCategoryCount(): void { if (static::count() > self::MAX_CATEGORIES) { throw new \Exception('Cannot create more than ' . self::MAX_CATEGORIES . ' category approaches.'); } } /** * Validate that the minimum number of category approaches is maintained. * * @throws \Exception If deletion would violate the minimum category requirement. */ protected static function validateMinCategoryCount(): void { if (static::count() <= self::MIN_CATEGORIES) { throw new \Exception('At least ' . self::MIN_CATEGORIES . ' category approach is required.'); } } /** * Perform any actions required after the model boots. */ protected static function booting(): void { static::creating(function (self $model) { $model->validateMaxCategoryCount(); }); static::updating(function (self $model) { $model->validateMaxCategoryCount(); }); static::deleting(function (self $model) { static::validateMinCategoryCount(); }); } /** * Get all section approaches associated with this category approach. */ public function sectionsApproaches(): HasMany { return $this->hasMany(SectionApproach::class, 'category_id'); } }