laravel blade concat属性

时间:2018-07-02 08:23:34

标签: laravel laravel-blade

@foreach($variationTypeCollection as $key => $var)

do some thing

@foreach($collection as $col)

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

@endforeach

@endforeach

如何使用键连接属性

我希望它看起来像variationId1,variationId2

谢谢。

2 个答案:

答案 0 :(得分:0)

尝试

@foreach($collection as $col)

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

@endforeach

提高可读性

@foreach($collection as $col)

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

@endforeach

答案 1 :(得分:0)

@foreach($collection as $col)

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

@endforeach

这可能会解决您的问题