I'm trying to parse a blade template string into php format and use eval() to evaluate string as php code
$array = [
'foo' => 'bar',
'bar' => 'foo'
];
$content = '@foreach($array as $value){{$value}}@endforeach';
$blade = Blade::compileString($content);
$php = eval($blade);
This is my code for testing so far and it throws exception
ParseError: syntax error, unexpected '<', expecting end of file
value of $blade after compileString()
<?php $__currentLoopData = $array; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $value): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><?php echo e($value); ?><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
What causes this error? Is eval() not compatible with the way compileString() is parsing blade into php?