Line Breaks In Laravel Blade

Websolutionstuff | Jul-26-2020 | Categories : Laravel PHP

In this post, I will show you how to break lines for Textarea in laravel blade. Many times when you save some text in the text area and save it into the database, but when you want to display or print the same data that time it is showing in the same single line and you didn't get proper output. So, at that time we are using PHP function nl2br() in the blade file.

Laravel helper provides many functionalities and you can use e Laravel helper function to purify your HTML before showing line breaks. whenever you want to preserve saved line breaks in the Textarea field in the laravel blade we are using the PHP nl2br() function. So, we will break code or newlines.

nl2br — Inserts HTML line breaks before all newlines in a string. The nl2br() function inserts HTML line breaks (<br> or <br />) in front of each newline (\n) in a string.

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

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

// OR

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

 

Recommended Post
Featured Post
How To Get Element By Data Attribute In jQuery
How To Get Element By Data Att...

In this article, we'll learn how to locate elements using data-attribute values. We can do this using jQuery and CSS...

Read More

Jul-11-2022

Laravel Datatables Example
Laravel Datatables Example

In this example, I will show you how to implement/install data tables in laravel. Datatables provides users with many fu...

Read More

May-16-2020

File Upload With Progress Bar In Angular 13
File Upload With Progress Bar...

In this article, we will see the file upload with a progress bar in angular 13. In this example, we will learn how to im...

Read More

Jun-11-2022

How To Validate Username And Password In React JS
How To Validate Username And P...

In this article, we will see how to validate username and password in react js. In this example, we will validate t...

Read More

Sep-13-2022