Websolutionstuff

Line Breaks In Laravel Blade

  • 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.
  • nl2br — Inserts HTML line breaks before all newlines in a string.
  • 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)) !!}

Example Using nl2br() Function

<?php
echo nl2br("This is\n demo");
?>

Output

This is<br />
demo

I am Laravel and PHP Developer. I have also Good Knowledge of JavaScript, jQuery, Bootstrap and REST API.