I want to execute the following echo:
echo '<div class="grid grid-cols-1 mt-4">
@foreach( $sectionOneCompare as $chart )
<livewire:is :component="$chart['type']">
@endforeach
</div>'
You'll notice the three levels of quotation nesting... this is what's stumping me. There's a million questions already asked about this, and they all say to escape like so:
echo "<div class=\"grid grid-cols-1 mt-4\">
@foreach( $sectionOneCompare as $chart )
<livewire:is :component=\"$chart['type']\">
@endforeach
</div>"
...but it does not work for me. Both ways, it fails to parse properly. How do I nest this correctly?
Edit: I left out of my original question that this echo is inside a PHP if statement:
<?php if ($sectionOne != null) {
// above code snippet
} ?>
Since I'm using Blade/Livewire, the answer ended up being to use a Blade conditional instead. That way I didn't have to nest quotes at all! Thanks to Qirel's comment for helping me realize this.
@if ($sectionOne != null)
// above code snippet
@endif