Support the ongoing development of Laravel.io →
posted 10 years ago
Views Blade

Hi!

I was wondering if it's correct to use the @include function inside a @foreach loop in a blade file (performance wise).

For exemple :

<ul>
@foreach
    @include('li_element')
@endforeach 
</ul>

I do that because I need to add (or update) elements to the list using ajax, and this way I can only render the subview and use it in my ajax response, instead of rendering the complete list.

But when the page load the first time, it has to do this @include a lot of time. Is this a problem?

I was thinking about creating a separate ajax_li_element file and use it to build my ajax response content. But that create one more file and some code duplication.

Thanks.

Last updated 3 years ago.
0

Sign in to participate in this thread!

PHPverse

Your banner here too?

MrShibby mrshibby Joined 1 Jul 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.