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.
Anil Bist
Skills Laravel
Qualifications :- High School - SLV, College/University - Graphic Era Deemed Univ University,Location :-Dehradun,Dehradun,Uttarakhand,India
Description:-
I started my Professional Journey in 2006 with one of the Web Development Company in Bangalore and my 1st framework was "Ruby on Rail" as Web development and delivered around 5+ Projects using this platform. Then came another dimension as JEE/Sturst framework, Gradually I realized that I want to build something on my own and give my passion and energy on creating something different a
Explore