如何根据Laravel 5.4中的属性名称对dropdown进行分组?

One product has multiple attributes, each combination represent an individual product. As you add variable products with variations in woocommerce (WordPress).

Now I've product attributes in array and confused how can I 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, so it should display in a one dropdown and other one should display on another drop down.

I know my logic is wrong here to print out drop downs can you guys help me ?

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

Thanks,

You could use collection to group the attributes by their type and then loop through them that way:

@foreach(collect($attributes)->groupBy('type') as $options)

    <label>{{ $options->first()->name }}</label>

    <select class="form-control">
        @foreach($options as $option)
            <option value="{{ $option->id }}">{{ $option->value }}</option>
        @endforeach
    </select>
@endforeach

You will need to sort the name attribute for the selects.

Hope this helps!