Hi, Im uploading multiple images for a product, on my project. Initially it was working fine then suddenly started throwing this error, "foreach() argument must be of type array|object, null given "; Below is the code snippet showing the error. Thank you for any valuable assistance.
foreach ($this->attribute_values as $key=>$attribute_value)
{
$avalues = explode(",", $attribute_value);
foreach ($avalues as $avalue)
{
$attr_value = new AttributeValue();
$attr_value->product_attribute_id = $key;
$attr_value->value = $avalue;
$attr_value->product_id = $product->id;
$attr_value->save();
}
}
Thank you @nakov and @aschmelyun ,so I wrapped the code in an if statement like this
if (is_array($this->attribute_values)){
foreach ($this->attribute_values as $key => $attribute_value) {
$avalues = explode(",", $attribute_value);
foreach ($avalues as $avalue) {
$attr_value = new AttributeValue();
$attr_value->product_attribute_id = $key;
$attr_value->value = $avalue;
$attr_value->product_id = $product->id;
$attr_value->save();
}
}
}