How to use nl2br() in Laravel / Blade


I want to keep the linebreaks in my view from data I'm receiving from my database. The data was saved from a textarea into the database. Now I want to keep the line breaks when using this value in blade. I'm using Laravel + Blade. I tried this but its not working:

{{ nl2br(e($textValue)) }}
HTML Software Question created: 2020-05-17 08:41 codeBrother


In Laravel 5 and later your can use: 

{!! nl2br(e($text)) !!}

For Laravel 4 try it this way:

{{ nl2br(e($text)) }}

e() will run htmlentities() on the given string and returns it as HTML entities. 

answered 2020-05-17 08:46 CodeReacher