php - Set dropdown option to active in Laravel -


hi trying set value of dropdown selected when user goes edit page of application getting error , realise because not have correct syntax.

this code:

<div class="form-group">             <label>category</label>             <select name="category_id" id="cat_drop">                 @foreach($cats $cat)                     <option value="{{$cat->id}} {{if($tip->category_id == $cat_id){ echo 'selected';} }}">{{$cat->name}}</option>                 @endforeach             </select>         </div> 

basically tips have category_id , dropdown allows user change tip category. selected category_id set value of dropdown.

i new laravel , blade templating engine appreciate help.

you can use ternary if:

@foreach($cats $cat)     <option value="{{$cat->id}}" {{($tip->category_id == $cat_id) ? 'selected':''}}>{{$cat->name}}</option> @endforeach 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -