I did a redirect in laravel:

return redirect('admin')->with($returnData);

$returnData is a string that contains a bootstrap info div with the result from the controller. Almost everything is working except when the page loads again it shows the html on the page as if it were text, brackets and everything. If I use this:

@if(!empty(Session::get('error'))) {{ Session::get('error')}} @endif

Then it shows is as pure text. If I change it to

<?php if(!empty(Session::get('error'))) { echo Session::get('error'); } ?>

它很好用.我可以这样保存它,但我宁愿使用Blade/Laravel作为应该使用的工具,所以我想知道是否有办法让@if语句显示呈现的html而不是文本版本?

推荐答案

I would recommend returning just the error message then in your view create the div. So if you were to change the layout of the view, you would it in one place.

@if(Session::has('error'))
<div class="alert alert-danger">
  {{ Session::get('error')}}
</div>
@endif

hope this help.

Laravel相关问答推荐

当两个外键都在同一个表上时创建直通关系

Laravel 9 如何将 url 中的参数从一个控制器传递到另一个控制器?

使用 laravel 根据当月显示注册用户列表

用户''@'localhost'对数据库'forge'的访问被拒绝随机出现

在 apache docker 容器中运行虚拟主机

Laravel 中的 index()" 是什么意思?

Laravel 5.4 中的自定义助手类

实施 Payum/Laravel 定期付款

用 laravel 表单确认删除?

Laravel 4 的 Cron 作业(job)

在 laravel 分页中添加一些数据

如何利用 StorageFacade 的 Filesystem 类的 glob 方法?

Heroku CLI 安装错误:PATH 未更新,原始长度 1585 > 1024

从 Artisan 电话中获得响应

laravel 搜索多个以空格分隔的单词

Lumen/Laravel 6:调用未定义的函数 array_except()

Laravel 中的 isDirty() 是什么意思?

将参数传递给过滤器 - Laravel 4

Laravel or where

如何使用 Postman 处理 Laravel $_POST 请求