belongsTo(Module::class); } public function lessons() { return $this->hasMany(Lesson::class)->orderBy('order'); } public function chapters() { return $this->hasMany(Chapter::class)->orderBy('order'); } public function getRouteKeyName() { return 'slug'; } protected static function boot() { parent::boot(); static::creating(function ($section) { if (empty($section->slug)) { // Use title + uniqid to avoid collisions $section->slug = Str::slug($section->title . '-' . uniqid()); } }); static::updating(function ($section) { if ($section->isDirty('title')) { // When renaming, regenerate slug based on title + id $section->slug = Str::slug($section->title . '-' . $section->id); } }); } }