如何删除 laravel blade 视图中逗号前的 space?

How to remove the space before a comma in laravel blade view?

@foreach($opt as $key => $o)
   @if($o == 1)A @endif
   @if($o == 2)B @endif
   @if($key+1 != count($opt)), @endif
@endforeach

如何显示预期输出 A、B、C?

//Current Output       A , B , C        
//Expected Output      A, B, C

你可以这样做:

@foreach($opt as $key => $o)
    {{ $o == 1 ? 'A' : '' }}{{ $o == 2 ? 'B' : '' }}@if($key+1 != count($opt)), @endif
@endforeach

我发现保持 blade 语法的可读性非常痛苦,所以我在 if/else 语句中复制了逗号之前的单词。

期望的输出:

<p>Some text goes here, with this conditional text</p>

Blade结构

<p>Some text goes
    @if($condition)
        here, with this conditional text
    @else
        here
    @endif
</p>