@php $colors = []; if(!empty($item->product_id)) { $colors = DB::table('product_variants')->whereNull('deleted_at')->whereNotNull('color_name')->where('price_incl_vat', '!=', 0)->where('approve', 1)->where('product_id', $item->product_id)->groupBy('color_name')->pluck('color_name')->toArray(); } $sizes = []; if(!empty($item->product_id)) { $sizes = DB::table('product_variants')->whereNull('deleted_at')->whereNotNull('size')->where('price_incl_vat', '!=', 0)->where('approve', 1)->where('product_id', $item->product_id)->groupBy('size')->orderBy('size_order')->pluck('size')->toArray(); } if(!empty($variant) && !empty($variant->color_name) && !in_array($variant->color_name, $colors)) { $colors[] = $variant->color_name; } if(!empty($variant) && !empty($variant->size) && !in_array($variant->size, $sizes)) { $sizes[] = $variant->size; } $first_color = $first_size = $first_variant = null; @endphp @if(empty($colors)) @else @php $first_color = $colors[0]; if(!empty($variant)) { $first_color = $variant->color_name; } @endphp @endif @if(empty($sizes)) @else @php $first_size = $sizes[0]; if(!empty($variant)) { $first_size = $variant->size; } @endphp @endif @php if(!empty($item->product_id)) { $first_variant = DB::table('product_variants') ->whereNull('deleted_at') ->where('size', $first_size) ->where('color_name', $first_color) ->where('price_incl_vat', '!=', 0) ->where('approve', 1) ->where('product_id', $item->product_id) ->first(); } @endphp @if(!empty($variant)) @else @endif @if(!empty($variant)) @endif