I work with Laravel v5.7 !
I have CourseController that controll all things about Courses . all things was ok but now i have problem . in my single page of courses any title or .. returned null .
public function single(Course $course)
{
$course = Course::get()->first();
$comments = $course->comments()
->where('approved', 1)
->where('parent_id', 0)->latest()
->with('comments')->get();
return view('Home.course', compact('course', 'comments'));
}
Here is my controller code . when i use first() at all my singlepage i have same title and image ,..... and if i delete the first() u have this error :
Method Illuminate\Database\Eloquent\Collection::comments does not exist.
I use {{ $course->title }} for showing course data in singlepage .
but for all slugs and courses return only first row of Db .
Please help me if you can ! ThankYou
You are currently overwriting the
$coursevariable with the first instance in the database.