Mar 31, 2022
0
Level 4
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.
Please or to participate in this conversation.