当管理员想要删除药物时,我在控制器中写下了以下代码:
$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);
在另一个刀片文件中,我有这个会话警报:
@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}}
,但一直将其作为纯文本。
正在显示的警报:
错了!您无权删除该药物所属的药物,{{$drug->drugStore->name}}
{{ $var }}
语法仅用于Blade文件。
在您的控制器中,您应该使用标准的PHP串联:
$msg = 'You .... to <a href="'. action('UserController@viewStore', $drug->drugStore->id) . '">' . $drug->drugStore->name . '</a>';
// ^^^^ ^^^^