Laravel 5 produces a session variable containing html in the blade

I did a redirection in laravel:

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

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

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

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

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

It works great. I support this well so, but I would rather use Blade / Laravel as it should have been used, so I was wondering if there is a way for the @if operator to display the displayed html rather than the text version?

+4
source share
4 answers

I would recommend returning only the error message and then creating a div in your view. Therefore, if you want to change the layout of the view, you would do it in one place.

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

hope this help.

+10
source

To display rendered HTML, you must use {!! $variable->coontent !!} {!! $variable->coontent !!} in your view, and this will convert your HTML text to render

+3
source

Try changing your blade code as follows.

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

Let this example help you. try it

  @if (session('Error')) <div class="alert alert-success"> {{ session('Error') }} </div> @endif 
0
source

All Articles