DEV Community

loading...

Line Breaks In Laravel Blade

websolutionstuff profile image Websolutionstuff Originally published at websolutionstuff.com ・1 min read
  • In this post I will show you how to break line for textarea in laravel blade.

  • Many times when you save some text in textarea and save into database, but when you want to display or print same data that time it is showing in same single line and you didn't get proper output. So at that time we are using PHP function nl2br() in blade file.

  • Laravel helper provide many functionalities and you can use e Laravel helper function to purify your html before showing line breaks.

  • You need to do the escaping first using e() and then after apply nl2br() function.

{{ nl2br(e($data)) }}

// OR

{!! nl2br(e($data)) !!}
Enter fullscreen mode Exit fullscreen mode

Example Using nl2br() Function

<?php
echo nl2br("This is\n demo");
?>
Enter fullscreen mode Exit fullscreen mode

Output

This is<br />
demo
Enter fullscreen mode Exit fullscreen mode

Read Also : How To Avoid TokenMismatchException On Logout

Discussion (0)

pic
Editor guide