刀片从数据库渲染

In my view I have this code:

{{L::getSomeContent('content')}}

This method returns content from the database. My question is, is it possible to return and render Blade straight from the database? For example, I have stored in the database:

<img src"{{asset('somepath')}}">

But when rendering this data straight from the database, it will just show like '%7%7'

I have tried Blade::compileString

I hate to suggest this, but eval would work in this case. Before you use this, you have to make sure that the content you pass to it isn't user input. And if it is you have to sanitize it (or trust the user, if the content can be changed in some kind of admin tool)

Instead of using this method you should maybe thinking of some other way to organize your content. For paths you could use a placeholder and just do a string replace before outputting.

Anyhow, be warned: eval() will execute any PHP code that's passed.

Here's a working example. Of course you put that in some kind of helper function to not clutter your view code, but I'll leave that to you.

<?php
    $blade = L::getSomeContent('content');
    $php = Blade::compileString($blade);
    // remove php brackets because eval() doesn't like them
    $php = str_replace(['<?php', '?>'], '', $php);
    echo eval($php);
?>

As I already mentioned for this particular case (a path to an asset) you could use a placeholder in your content. For example:

Stored in the database

<img src"%ASSET%some/path">

And then inside a helper function and before output, just replace it with the real path:

$content = L::getSomeContent('content');
$html = str_replace('%ASSET%', asset(''), $content);

I found the answer in the comments @blablabla :

protected function blader($str, $data = array())
{
    $empty_filesystem_instance = new Filesystem;
    $blade = new BladeCompiler($empty_filesystem_instance, 'datatables');
    $parsed_string = $blade->compileString($str);
    ob_start() and extract($data, EXTR_SKIP);
    try {
        eval('?>' . $parsed_string);
    }
    catch (\Exception $e) {
        ob_end_clean();
        throw $e;
    }
    $str = ob_get_contents();
    ob_end_clean();
    return $str;
}

This part seems to be working fine:

Blade::compileString($yourstring);
eval('?>' . $yourstring);