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
Angular 13 Crop Image Before Upload With Preview
Angular 13 Crop Image Before U...

In this article, we will see the angular 13 crop image before uploading with a preview. we will give you a sim...

Read More

May-10-2022

Laravel 9 Authentication Using Inertia JS
Laravel 9 Authentication Using...

In this article, we will see laravel 9 authentication using inertia js. Here, you can learn how to authenticat...

Read More

Dec-05-2022

How To Add Action Button In Angular 15 Material Datepicker
How To Add Action Button In An...

In this tutorial, I will guide you through the process of adding an action button to the Angular 15 Material datepicker...

Read More

Jul-07-2023

Laravel Clear Cache Using Artisan Command
Laravel Clear Cache Using Arti...

In this tutorial, I am giving information about laravel artisan command which can help you to clear your application'...

Read More

May-18-2020