public function comments() {
return $this->hasMany('Comment','comment_id','id');
}
First argument of hasMany should be full class name, like App\Comment. Second argument should be the name of the field in comments table that references the parent Post, like post_id. If this field in your comments table is already called post_id, you can skip the second, and probably third, arguments, and just write:
return $this->hasMany('App\Comment');
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.