Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

Show comments() method of your Post class.

0
public function comments() {
        return $this->hasMany('Comment','comment_id','id');
    }
0

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');
Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

alvi1987 alvi1987 Joined 20 Jan 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.