lundi 28 décembre 2015

laravel hasMany comments from a blog relationship

Im very new at using laravel so please be gentle. I have a blog, that has comments. Im using the hasMany to return the comments but I keep getting an empty array.

I have 2 tables; 1) Blog 2) Comments

The comments table tied the blog comment to the correct blog using a blog_id column in the table.

In my Blog model I am calling the following:

public function comments() {
    return $this->hasMany('App\Models\Comments', 'blog_id', 'id');
}

But I am getting an invalid argument for foreach. I have tried only using the frogein key, but still no luck.

As I said im new to using laravel and I hope you can understand where im coming from.

Thanks for any help!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire