protected function getColorsOfProduct($array) { if (!is_array($array)) { $array = explode(",", $array); } if (count($array) > 1) { $count = 0; $colors = Color::select('id', 'name', 'image', 'code')->where('code', strtoupper($array[0])); foreach ($array as $item) { if ($count > 0) { $colors_union = Color::select('id', 'name', 'image', 'code')->where('code', strtoupper($item)); $colors = $colors->unionAll($colors_union); } $count++; } $results = $colors->orderBy('name', 'asc')->get(); return $results; } else { $results = Color::select('name', 'image')->where('code', $array)->get(); return $results; } }