1For example, a blog post may have an infinite number of comments. And a single
2comment belongs to only a single post
3
4class Post extends Model
5{
6 public function comments()
7 {
8 return $this->hasMany('App\Models\Comment');
9 }
10}
11
12class Comment extends Model
13{
14 public function post()
15 {
16 return $this->belongsTo('App\Models\Post');
17 }
18}
1$movies = Movie::whereHas('director', function($q) {
2 $q->where('name', 'great');
3})->get();
4