Hey, I've an idea that I want to add modal structures through includes in my app. My problem now is that a modal can be added from several pages in the app, and there is a chance of "overlapping" modals. I mean that the modal can be added more than once because of the page structure.
I want to avoid the duplicate includes in the HTML structure some how, but allow for multiple @include for a certain modal, to make sure it's added. Is there any way of achieving this?
So far I have been without luck.
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