utdev
utdev

Reputation: 4102

Laravel line break in message

How do I do a line break in a message.

I tried following

$request->session()->flash('message', "first line \r\n second line");
$request->session()->flash('message', "first line <br> second line");

but they did not work, how do I accomplish this?

Upvotes: 5

Views: 24787

Answers (4)

cawecoy
cawecoy

Reputation: 2419

If you want to use escaped echoing, you can try:

@foreach(explode('<br>', session('message')) as $msg)
{{ $msg }}
@if(!$loop->last)
<br>
@endif
@endforeach

Upvotes: 2

AddWeb Solution Pvt Ltd
AddWeb Solution Pvt Ltd

Reputation: 21681

You can try:

{!! 'first line <br> second line' !!}

Output

first line
second line

And

{!! nl2br(e('first line <br> second line')) !!}

Output

first line <br> second line

Upvotes: 6

Alexey Mezenin
Alexey Mezenin

Reputation: 163798

Use <br> but when displaying the messages, use unescaped echoing:

{!! session('message') !!}

https://laravel.com/docs/5.3/blade#displaying-data

Upvotes: 13

Niklesh Raut
Niklesh Raut

Reputation: 34914

Displaying Unescaped Data in laravel like this.

{!! $message !!}

Upvotes: 1

Related Questions