dimanche 18 novembre 2018

Laravel, too many queries, if I manipulate the returned Eloquent collection

I'm using Laravel 5.7 and some of basic relations between 2 tables

when I try to do anything with the returned Eloquent collection,
I find the DebugBar records a lot of queries

like this example:

$articles = \App\Article::get();
return count($articles->toArray());
// DebugBar records about 395 queries

On the contrary, If use the collection counting helper

$articles = \App\Article::get();
return $articles->count();
// DebugBar records only 2 queries



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire