user6369603
user6369603

Reputation:

Showing whitespace from text (Laravel 5.3)

Users have been adding breaks for their paragraphs which can be seen in the database when looking at their text columns, like this:

enter image description here

However, when I display the text on their profile pages, like this:

<h5>{{ $user->description }}</h5>

The text simply displays as one large paragraph. I am looking to have the line breaks in the database show on the page to split up the paragraph.

Upvotes: 2

Views: 1722

Answers (2)

Chris
Chris

Reputation: 58142

This is most likely a CSS issue rather than a Laravel specific issue. You should try set that element to honor white-space:

h5 {
    white-space: pre-wrap;
}

white-space: pre is also an option.

You can see here for the variances between the white-space options: https://css-tricks.com/almanac/properties/w/whitespace/

Upvotes: 2

user3743266
user3743266

Reputation: 1172

In your database the field probably has "\n" as newline so to see it in HTML, you need to change "\n" to <br>, try this: http://php.net/manual/en/function.nl2br.php

Upvotes: 0

Related Questions