我正在插入一个包含多个输入的数组。但是当我添加或创建它时,它不会插入或返回任何值。在这种情况下如何使用 create ?我是 Laravel 的新手。
foreach ($data['sku'] as $key => $val) {
$attrCountSKU = ProductsAttribute::where('sku', $val)->count();
if ($attrCountSKU > 0) {
return back()->with('error', 'SKU already exists for this product! Please input another SKU.');
}
$attrCountSizes = ProductsAttribute::where(['product_id' => $product->id, 'size' => $data['size'][$key]])->count();
if ($attrCountSizes > 0) {
return back()->with('error', 'Size already exists for this product! Please input another Size.');
}
$attribute = new ProductsAttribute;
$attribute->product_id = $product->id;
$attribute->sku = $val;
$attribute->size = $data['size'][$key];
$attribute->price = $data['price'][$key];
$attribute->stock = $data['stock'][$key];
dd($attribute);
dd($attribute->create());
}
呼如林