Here is how @include works (compileInclude method):
https://github.com/illuminate/view/blob/master/Compilers/BladeCompiler.php
Extend blade creating your @includeonce tag:
I had same issue. What slillo recommended is over-complicated in my opinion. Just declare a variable in an Util class.
Add this to your Util.php
public static $isReportModalIncluded = false;
then in your blade do this
@php
//include this only once
if (\App\Classes\Utils::$isReportModalIncluded === true) {
return;
}
if (\App\Classes\Utils::$isReportModalIncluded === false) {
\App\Classes\Utils::$isReportModalIncluded = true;
}
@endphp
Hopefully Laravel will introduce an @includeonce in the future
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community