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
Vue Js Get Array Of Length Or Object Length
Vue Js Get Array Of Length Or...

In this tutorial, we will see you example of vue js get an array of length or object length. we will learn about vu...

Read More

Jan-07-2022

How To Get Current Month Records In MySQL
How To Get Current Month Recor...

In this tutorial, we will see how to get current month records in MySQL. For data analysis and reporting, we need more d...

Read More

Feb-08-2022

How to Change Date Format in Laravel 11
How to Change Date Format in L...

Hello developers! In this article, we'll see how to change the date format in laravel 11. Here, we'll learn...

Read More

Apr-29-2024

Laravel 10 Login and Registration with Auth
Laravel 10 Login and Registrat...

Welcome to my guide on creating a secure and visually appealing user authentication system in Laravel 10! Laravel, one o...

Read More

Aug-23-2023