I have made a dynamic select element in Laravel 5.7, this is my code:
<select>
@foreach($sbj_topics as $sbj_topic)
<option value="{{ $sbj_topic->id }}">{{ $sbj_topic->sbj_topic_name }}</option>
<optgroup label="________________"></optgroup>
@endforeach
</select>
What I need not display ________________
after the last item. I tried end(), key() methods but all in vain, can anyone let me know how to do this?
Current Result:
option1
_______
option2
_______
option3
_______
I need:
option1
_______
option2
_______
option3
you can use the $loop variable https://laravel.com/docs/5.7/blade#the-loop-variable
<select>
@foreach($sbj_topics as $sbj_topic)
<option value="{{ $sbj_topic->id }}">{{ $sbj_topic->sbj_topic_name }}</option>
@if (!$loop->last)
<optgroup label="________________"></optgroup>
@endif
@endforeach