I'm trying to pass a JS variable via .innerHTML method into the blade command @include in Laravel and Laravel won't have anything to do with it.
Here is my JS function:
<script type="application/javascript" >
function itemFeatures(divId, subCatId){
axios.get('/item-type/' + subCatId.value)
.then(function (response){
let itemName = response.data[0].name;
document.getElementById(divId).innerHTML = `@include('gearitem.itemtype.${itemName}')`
})
}
</script>
I have a blade who's address is gearitem.itemtype.tent.blade.php for example and the 'response.data[0].name' yields 'tent' so logically i'd expect the variable itemName to place 'tent' at the appropriate place in the @include string but instead I'm getting the following error from Laravel:
gearitem.itemtype.${itemName} was not found. Are you sure the view exists and is a .blade.php file?
I have tested the blade by hard coding it so = @include('gearitem.itemtype.tent') inside the div without a problem (it appears correctly) I also tried an .innerHTML = <p>${itemName}</p>
and the string 'tent' appears in the div perfectly. It seems like Laravel is meddling with my syntax inside the JS before it is even rendered for some reason... What am i missing here?