// your relationship
public function books() {
return $this->hasMany('App\Models\Book');
}
// Get the first inserted child model
public function first_book() {
return $this->hasOne('App\Models\Book')->oldestOfMany();
}
// Get the last inserted child model
public function last_book() {
return $this->hasOne('App\Models\Book')->latestOfMany();
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter