laravel blade concat property

问题描述 投票:1回答:2
@foreach($variationTypeCollection as $key => $var)

do some thing

@foreach($collection as $col)

{{ $col->variationId.$key++ }}

@endforeach

@endforeach

如何使用密钥连接属性

我希望它看起来像变异Id1,变异Id2

谢谢。

laravel laravel-blade
2个回答
0
投票

试试这个

@foreach($collection as $col)

    {{ $col->{'variationId' . $key++ } }}

@endforeach

为了更好的可读性

@foreach($collection as $col)

    @php($property = 'variationId' . $key++) 
    {{ $col->{$property} }}

@endforeach

0
投票
@foreach($collection as $col)

{{ $col->variationId }}{{ $loop->iteration }}

@endforeach

这可能会解决您的问题

© www.soinside.com 2019 - 2024. All rights reserved.