Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kastony's avatar

Blade strips spaces inside variable

Hi, in my view I have a

{{ $invoice->a46 }} 

my controller

$invoice =  Invoice::find($id);  
return View('pdf.invoice', compact('invoice'))

instead of showing 05/15 (5 spaces) 20/11/15 (10 spaces) 1.789,00 (5spaces) 47,10 it shows 05/15 20/11/15 1.789,00 47,10 I don't know why it's strips the spaces.

Any suggestions ?

P.S. posting here also removes the spaces.

0 likes
7 replies
ohffs's avatar

HTML isn't 'space sensitive' - so putting < space>< space>< space> will just display as < space>. You could use a < pre> tag if you really want to do that though.

ian_h's avatar

Hi..

This would resolve it:

{{ str_replace(' ', '&nbsp;', $invoice->a46 }}

Cheers..

Ian

2 likes
Snapey's avatar

hey, I can remember back in 2001 using spaces to pad content

I have to come clean and say I also used spacer gifs for a while as well.

There... got it off my chest.

2 likes
jekinney's avatar

The curly braces translate to php echo statement. That's it so it's not blade causing the issue its your format that is.

jlrdw's avatar

@snapey how quaint.

Nothing wrong with with a &nbsp now and then, I use to put a small space between two buttons at times. Just don't over use.

Please or to participate in this conversation.