I want to have a dynamic component that can conditionally render child dynamic components.
Let’s imagine having a parent component
In my view blade this is then called something like this
(Of course, this wouldn’t be parent but a method that resolves that name)
<x-dynamic-component :elements="$elements" component="parent" />
Within that component, based on the $elements variable, it should render other dynamic components
$element could be for instance
So what I’m trying to do within my parent component is this:
<div> @foreach($elements as $element) @if($element->hasDynamicComponent()) <x-component-dynamic :component="$element->getComponentName()" /> @endif @endforeach
The problem is, that Laravel nevertheless parses those lines regardless of this if statement.
I’m getting the following error message:
Unable to locate a class or view for component [component-dynamic]. (View: …..)
This is because
false and therefore
getComponentName is empty. Of course Laravel cannot resolve a component without a name.
The thing is Laravel shouldn’t even try to resolve this, because
hasDynamicComponent is false.