Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rajeshtva's avatar

remove implicit nested route binding for a route.

I have a route of this kind /{user:username}/{course:slug}/invoice. this url is used to generate invoices. {user:username} is for user who purchased a course and {course:slug} is the slug for course which the user purchased. so the model relationship looks like this.

// User.php
class User extends Model 
{
		// for the user who purchased course. 
		public function registeredCourses() {
				return $this->belongsToMany(Course::class); // for students
		}

		// for the user who created course like instructor,
		public function courses(){
				return $this->hasMany(Course::class); // for users.
		}
}

course.php

class Course extends Model 
{
			public function registeredCourses(){
						return $this->belongsToMany(User::class); // for students.
			}
			
			public function courses()
			{
						return $this->belongsTo(User::class); // for instructors.
			}
}

also each user can register for any course only once.

how can i get route model binding to work in this scenario. at least disable implicit route model binding for disable for this route.

thank you.

0 likes
0 replies

Please or to participate in this conversation.