0

This seems simple yet I'm struggling with this. I'd like to get all these data {TotalRaces} separated by a comma for a Sparkline graph, however the leading or trailing comma will either cause a value of 0 at the beginning or the end of the sparkline (for an example). Any thoughts of how to remove the first, or last, comma? I need them in between the variables but not a the beginning or end.

Appreciate any help. Thanks!!

 @forelse ($pts as $p)
    ,{{ $p->TotalRaces }}   //causes zero at beginning of sparkline
 @empty

 @endforelse

OR

 @forelse ($pts as $p)
    {{ $p->TotalRaces }},   //causes zero at end of sparkline
 @empty

 @endforelse
4

2 回答 2

1

假设 $pts 是一个集合

{{ implode(',', array_map(function($a){return $a['TotalRaces'];}, $pts->toArray())) }}

你想要TotalRaces一个数组中的所有内容,以便用逗号将它们内爆。因此,您将$pts集合转换为数组,并将其传递array_map给以提取TotalRaces属性。

于 2015-12-04T07:53:13.160 回答
0

也许有点丑陋的代码,但仍然:

 @forelse ($pts as $p)
 {{ $p->TotalRaces }} @if($p != end($pts)),   @endif
 @empty
于 2015-12-04T07:46:55.860 回答