belongsTo(LessonSection::class); } public function lessons() { return $this->hasMany(Lesson::class)->orderBy('order'); } protected static function booted() { static::creating(function ($chapter) { if (empty($chapter->slug)) { $chapter->slug = Str::slug($chapter->title); } }); static::updating(function ($chapter) { if ($chapter->isDirty('title')) { $chapter->slug = Str::slug($chapter->title); } }); } public function getRouteKeyName() { return 'slug'; } }