如何查看特定课程的科目

I have a list of courses and in each course there is a buttonthat allows me to view all subjects of that particular course.

First, I used this command so laravel already know what the parent element is:

php artisan make:controller CourseSubjectController --model=Subject --parent=Course

In the course index.php file I have the button that should allow me to view all the subjects for that particular:

<td><a class="btn btn-success" href="{{route('departments.course.subjects.index', [$course->department->id, $course->id])}}">Subjects</a></td>

Apparently the url is correct:

The controller looks like this:

public function index(Course $course)
{
    return $course->subjects;
}

When I visit the link I encounter this error:

"Type error: Argument 1 passed to App\Http\Controllers\CourseSubjectController::index() must be an instance of App\Course, string given"

How can I view the subjects of the course?

Thanks in advance

It throws an error because you didn't pass a Course instance to your route. I assume you are using GET request and in your route you are only passing the course department id and its id :

[$course->department->id, $course->id]

So maybe you could do this in your controller instead :

public function index($departmentId, $courseId)
{
    $course = Course::findOrFail($courseId);
    return $course->subjects;
}