AucT's avatar
Level 2

Eager Loading and views

I'm using eager loading for displaying 15 items (using pagination) with 2 many-to-many relations for each.

It's working fine when I render them as json but when I use them in view it seems as it is ignoring them and gets it from database.

As response time for json is <500ms and response time for view generated is 5-6seconds.

  • How can I detect exactly what is going on?
  • Is there any other syntax for looping through eager loaded items

here what I use in view

@foreach($item->tags as $tag)
 {{ $tag->name  }}
@endforeach
0 likes
2 replies
AucT's avatar
AucT
OP
Best Answer
Level 2

I've tested with this. Everythings fine now. Probably some cached view with one more query *15 inside view.

\Event::listen('Illuminate\Database\Events\QueryExecuted', function ($query) {
            var_dump($query->sql);
            var_dump($query->bindings);
            var_dump($query->time);
        });

Please or to participate in this conversation.