vendredi 29 janvier 2016

Elequent Relationships Error

I have created a posts table & comments table for posts comments. I want to get my posts with their comments ...

In my Post Model :

public function comments()
{
     return $this->hasMany('App\Comment');
}

In my Comment Model :

public function post()
{
  return $this->belongsTo('App\Post');
}

And this is my Controller :

$post = Post::findOrFail($ID)->comments;
return view('show', compact('post'));

But I get this error : Undefined property: Illuminate\Database\Eloquent\Collection::$ID

What is my problem ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire