Answers for "lazy loading in laravel"

PHP
0

lazy loading in laravel

$books = App\Book::all();

foreach ($books as $book) {
    echo $book->author->name;
}
Posted by: Guest on September-25-2021
0

lazy loading in laravel

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Book extends Model
{
    /**
     * Get the author that wrote the book.
     */
    public function author()
    {
        return $this->belongsTo('App\Author');
    }
}
Posted by: Guest on September-25-2021

Browse Popular Code Answers by Language