15.3 Eloquent Models
Right, you know exactly how to create Eloquent models, so let’s just have a look at the source.
1 <?php
2
3 class User extends Eloquent
4 {
5 public function posts()
6 {
7 return $this->has_many('Post');
8 }
9 }
10
11 class Post extends Eloquent
12 {
13 public function author()
14 {
15 return $this->belongs_to('User', 'author_id');
16 }
17 }
Nice and simple, we have our User object which has_many posts, and our Post object which
belongs_to a user.