I have relationship between Video Category and Video Courses, one Category can Have many courses, I want to get video courses through video category item but getting error
Video Category Model
class VideoCategory extends Model
{
public function video_courses(){
return $this->hasMany('App\VideoCourse');
}
}
Video Course Model
class VideoCourse extends Model
{
public function video_category()
{
return $this->belongsTo(VideoCategory::class);
}
}
My View
@forelse ($category->video_courses as $video_course)
<a href="#"">{{$course->title}}</a>
@empty
<p>No Video Courses Available</p>
@endforelse
Error:
(4/4) ErrorException
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'video_courses.video_category_id' in 'where clause' (SQL: select * from video_courses
where video_courses
.video_category_id
= 2 and video_courses
.video_category_id
is not null and video_courses
.deleted_at
is null) (View: C:\xampp\htdocs\QuickLMS\resources\views\category.blade.php)
$courses = VideoCategory::find(1)->video_courses
. And make sure it returns collection. Then look for the following answers. – unclexo