dimanche 13 mars 2016

Find last iteration of foreach loop in laravel blade

In blade template i use last() method to find last iteration of foreach loop:

@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?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire