lazy loading in laravel

Solutions on MaxInterview for lazy loading in laravel by the best coders in the world

showing results for - "lazy loading in laravel"
Agustín
19 Aug 2020
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}
Tracey
16 Jan 2018
1$books = App\Book::all();
2
3foreach ($books as $book) {
4    echo $book->author->name;
5}