2

Is there any way when your text is too long - and you break it up with new lines - to not have whitespace happen? What I need is three values to be joint without whitespace in between.

<div style='font-size:100%; color:blue'>
    {{ $record->m_pk_address_line1 }}
    {{ $record->m_pk_address_line2 }}
    {{ $record->m_pk_address_line3 }}
</div>

Without entering new line, it'll be too long even if they can be joined together.

<div style='font-size:100%; color:blue'>{{ $record->m_pk_address_line1 }}{{ $record->m_pk_address_line2 }}{{ $record->m_pk_address_line3 }}</div>

Is there no standard way of going about this without resorting to tricks? What do people do when their code is too long and they need to break it up into new lines but they don't want the whitespace that comes with it?

Ben Kao
  • 621
  • 3
  • 8
  • 18

4 Answers4

1

You could make an accessor in the model of $record

public function getFullAddressAttribute($value)
{
    return $record->m_pk_address_line1 . $record->m_pk_address_line2 . $record->m_pk_address_line3;
}

and use that in your views like this

$record->full_address;
Douwe de Haan
  • 6,247
  • 1
  • 30
  • 45
1

you have two tricks to avoid whitespace, the first is html comments:

<div style='font-size:100%; color:blue'>
     {{ $record->m_pk_address_line1 }}<!--
  -->{{ $record->m_pk_address_line2 }}<!--
  -->{{ $record->m_pk_address_line3 }}
</div>

the second is font-size: 0

.container {
  font-size: 0;
}
.container > * {
  font-size: 1rem; /** or whatever suits your needs **/
}
Kustolovic
  • 172
  • 6
0

For removing whitespaces use

$string= preg_replace('/\s+/', '', $string);

<div style='font-size:100%; color:blue'>
    {{ preg_replace('/\s+/', '', $record->m_pk_address_line1 }}
    {{ preg_replace('/\s+/', '', $record->m_pk_address_line1 }}
    {{ preg_replace('/\s+/', '', $record->m_pk_address_line1 }}
</div>
Rahul
  • 2,374
  • 2
  • 9
  • 17
  • The whitespaces are resultant of the newlines, this would only affect the input from `m_pk_*` – Rogue Jun 10 '17 at 05:12
0

Concatenate all three items:

<div style='font-size:100%; color:blue'>
    {{ $record->m_pk_address_line1.$record->m_pk_address_line2.$record->m_pk_address_line3 }}
</div>
Govind Samrow
  • 9,981
  • 13
  • 53
  • 90