I don't know what you are after but, I don't see the need to check that.
I'm guessing that you want to fetch something that belongs to the course that you pass the id for?
You can use route model binding like this
public function index(Course $course)
{
return view(lessons.index)->with([
'course' => $course
'lessons' => $course->lessons
]);
}
Or you can just query with the course id.
public function index($courseId)
{
return view('lessons.index')->with([
'lessons' => Lesson::where('course_id', $courseId)->get()
]);
}
The show method I guess is showing a single lesson, if so there is no need to see if it belongs to a course. The lesson either exist or it doesn't.
If you want to make 100% sure that the lesson belongs to the course you can
public function show($courseId, $lessonId)
{
return view('lessons.show')->with([
'lesson' => Lesson::where('course_id', $courseId)
->where('id', $lessonId)->get()
]);
}