php - how to group drop downs based on attributes names in Laravel 5.4? -


one product has multiple attributes, each combination represent individual product. add variable products variations in woocommerce (wordpress).

now i've product attributes in array , confused how can create multiple drop downs based on multiple categories.

array:3 [▼   0 => array:3 [▼     "id" => 13     "name" => "size"     "value" => "small"   ]   1 => array:3 [▼     "id" => 14     "name" => "size"     "value" => "large"   ]   2 => array:3 [▼     "id" => 19     "name" => "color"     "value" => "white"   ] ] 

as index 0, 1 has same name "size" having different values, should display in 1 dropdown , other 1 should display on drop down.

i know logic wrong here print out drop downs can guys me ?

<select class="form-control" id="attribute" name="attribute[]" style="width:70%;"> @foreach($attributes $attribute) <option value="">select {{  $attribute->name }}</option> <option value="{{ $attribute->id }}">{{ $attribute->value }}</option> @endforeach </select> 

thanks,

you use collection group attributes type , loop through them way:

@foreach(collect($attributes)->groupby('type') $options)      <label>{{ $options->first()->name }}</label>      <select class="form-control">         @foreach($options $option)             <option value="{{ $option->id }}">{{ $option->value }}</option>         @endforeach     </select> @endforeach 

you need sort name attribute selects.

hope helps!


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -