php - Eloquent ORM dynamic relation properties vs method for eager loading -


i'm using eloquent in slim framework. take advantage of eager loading. wonder there difference between using property , method.

the reason i'm asking because i'm using twig template engine , can call method.

will able take advantage of eager loading using property or not?

$obj = new book(); $books = $books->with('author')->get();  // using property foreach ($books $book) {     echo $book->author->name; }  // using method foreach ($books $book) {     echo $book->author()->get()->name; } 

there huge difference. in second line populated $books authors. , when iterating through them in first foreach have data, don't perform additional sql queries. eager loading made for.

but in second foreach calling get() method on every iteration , laravel starts repopulating authors making queries on , on every book.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -