I have a string returned to one of my views, like this:
$text = \'Lorem ipsum dolor
you can do with many ways in laravel 5..
{!! $text !!}
{!! html_entity_decode($text) !!}
Use {!! $text !!}
to display data without escaping it. Just be sure that you don’t do this with data that came from the user and has not been cleaned.
There is another way. If object purpose is to render html you can implement \Illuminate\Contracts\Support\Htmlable
contract that has toHtml()
method.
Then you can render that object from blade like this: {{ $someObject }}
(note, no need for {!! !!}
syntax).
Also if you want to return html property and you know it will be html, use \Illuminate\Support\HtmlString
class like this:
public function getProductDescription()
{
return new HtmlString($this->description);
}
and then use it like {{ $product->getProductDescription() }}
.
Of course be responsible when directly rendering raw html on page.
If you use the Bootstrap Collapse class sometimes {!! $text !!}
is not worked for me but {{ html_entity_decode($text) }}
is worked for me.
You can try this:
{!! $text !!}
You should have a look at: http://laravel.com/docs/5.0/upgrade#upgrade-5.0
Try this, It's worked:
@php
echo $text;
@endphp