Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Gun22's avatar

PHP code from a table

Hi, Is there any way to get php code from a mysql table, and run it in a blade template?

0 likes
10 replies
Gun22's avatar

But I don't know how it have to do.

thisismyaim's avatar

I don't think you can execute much , here is example you can search something like this:

$x = 'php test.php';
exec($x, $message);
print_r($message);

and can see output using message variable, i didn't tried this with mysql but with file it's working.

petrit's avatar

Just start writing php syntax like you do on php file. Blade will recognize php code

...
<?php
echo "hello world";
?>
...
Gun22's avatar

It is commented in HTML viewer:

?php echo "hello world"; ? -->
cimrie's avatar

@Gun22 It is likely that Blade is escaping the text to prevent unexpected code in the output. Try {!! $output !!} instead of {{ $output }} (where $output is whatever code you are trying to execute). Untested but would make sense to me :)

Hope it helps

Gun22's avatar

Not working, i've got 4.2... Some tips?

sinalco's avatar

With Laravel 4.*, you must use the following syntax to disable escaping in Blade views:

{{{ $output }}}

And the new syntax since Laravel 5+:

{!! $output !!}

You can find more information in the Laravel documentation.

willvincent's avatar

Is there any way to get php code from a mysql table, and run it in a blade template

Possible? Certainly... but this is a VERY bad idea.

Please or to participate in this conversation.