1<?php
2
3namespace App;
4
5use Illuminate\Database\Eloquent\Model;
6
7class Book extends Model
8{
9 /**
10 * Get the author that wrote the book.
11 */
12 public function author()
13 {
14 return $this->belongsTo('App\Author');
15 }
16}
1$books = App\Book::all();
2
3foreach ($books as $book) {
4 echo $book->author->name;
5}