在blade template中,我使用last()方法查找foreach循环的最后一次迭代:
@foreach ($colors as $k => $v)
<option value={!! $v->id !!} {{ $colors->last()->id==$v->id ? 'selected':'' }} > {!! $v->name !!} </option>
@endforeach
Is it ok? Perhaps there is a Laravel-style way to do the same?