我有一个
blade page
,它显示来自我的 Database
: 的 HTML 内容
{!! $htmlContent !!}
这段代码很好地渲染了 HTML。
但是在该变量内部,我使用的是这样的刀片代码:
<a href="{{ env('app_url') }}/shares"><img src="{{ asset('asset/img/shares.png') }}" /></a>
问题是链接(不起作用)和图像都没有出现。
如何解决这个问题?
要解决此问题,您可以在显示 HTML 内容之前使用 str_replace 函数将这些 Blade 指令替换为其实际值。以下是如何做到这一点的示例:
// Get the HTML content from the database
$htmlContent = // Fetch your HTML content from the database here
// Replace Blade directives with their actual values
$htmlContent = str_replace('{{ env('app_url') }}', config('app.url'), $htmlContent);
$htmlContent = str_replace('{{ asset('asset/img/shares.png') }}', asset('asset/img/shares.png'), $htmlContent);
// Display the HTML content
{!! $htmlContent !!}