This repository has been archived by the owner on Feb 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Example Eloquent Models
iverberk edited this page Dec 28, 2014
·
2 revisions
The following Eloquent models will be used as examples throughout the documentation:
class Husband extends Eloquent {
/**
* @return \Illuminate\Database\Eloquent\Relations
*/
public function wife()
{
return $this->hasOne('Wife');
}
/**
* @return \Illuminate\Database\Eloquent\Relations
*/
public function children()
{
return $this->hasMany('Child', 'father_id');
}
}
class Wife extends Eloquent {
/**
* @return \Illuminate\Database\Eloquent\Relations
*/
public function husband()
{
return $this->belongsTo('Husband');
}
/**
* @return \Illuminate\Database\Eloquent\Relations
*/
public function children()
{
return $this->hasMany('Child', 'mother_id');
}
}
class Child extends Eloquent {
/**
* @return \Illuminate\Database\Eloquent\Relations
*/
public function mother()
{
return $this->belongsTo('Wife');
}
/**
* @return \Illuminate\Database\Eloquent\Relations
*/
public function father()
{
return $this->belongsTo('Husband');
}
/**
* @return \Illuminate\Database\Eloquent\Relations
*/
public function toys()
{
return $this->belongsToMany('Toy');
}
}
class Toy extends Eloquent {
/**
* @return \Illuminate\Database\Eloquent\Relations
*/
public function children()
{
return $this->belongsToMany('Child');
}
}