在 Blade 中包含 HTML
Including HTML in Blade
当管理员想要删除药物时,我在控制器中编写了这段代码:
$msg = 'You are not authorized to delete this drug the drug belongs to ,<a href="'. action('UserController@viewStore',$drug->drugStore->id) . '"> {{$drug->drugStore->name}}</a>';
return redirect()->back()->with('error', $msg);
在另一个 Blade 文件中我有这个会话警报:
@if(session()->has('error'))
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<strong>Wrong!</strong> {!!session('error')!!}.
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
@endif
已成功创建 href,但我正在尝试添加 {{$drug->drugStore->name}}
但一直将其视为纯文本。
正在显示的警报:
Wrong! You are not authorized to delete this drug the drug belongs to , {{$drug->drugStore->name}}.
{{ $var }}
语法仅用于 Blade 文件。
在您的控制器中,您应该使用标准 PHP 连接:
$msg = 'You .... to <a href="'. action('UserController@viewStore', $drug->drugStore->id) . '">' . $drug->drugStore->name . '</a>';
// ^^^^ ^^^^
当管理员想要删除药物时,我在控制器中编写了这段代码:
$msg = 'You are not authorized to delete this drug the drug belongs to ,<a href="'. action('UserController@viewStore',$drug->drugStore->id) . '"> {{$drug->drugStore->name}}</a>';
return redirect()->back()->with('error', $msg);
在另一个 Blade 文件中我有这个会话警报:
@if(session()->has('error'))
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<strong>Wrong!</strong> {!!session('error')!!}.
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
@endif
已成功创建 href,但我正在尝试添加 {{$drug->drugStore->name}}
但一直将其视为纯文本。
正在显示的警报:
Wrong! You are not authorized to delete this drug the drug belongs to , {{$drug->drugStore->name}}.
{{ $var }}
语法仅用于 Blade 文件。
在您的控制器中,您应该使用标准 PHP 连接:
$msg = 'You .... to <a href="'. action('UserController@viewStore', $drug->drugStore->id) . '">' . $drug->drugStore->name . '</a>';
// ^^^^ ^^^^