Why are you sending an array at a firstornew? This is basically a string that you are building an array with in the eloquent. Inserting an array will not work. Really the product_id should be a unique so you only need that value in your where.
So it would be something like this...
firstOrNew(['product_id' => $product_id]);
$product_id being the variable of the unique id. Then if you have tons of products to add just loop over the array of product ids and it will either make a new row at your save or update the product when it finds it first.
发布评论
评论(1)
为什么要在Firstornew发送阵列?这基本上是您在雄辩中构建一个数组的字符串。插入阵列将行不通。真的,product_id应该是唯一的,因此您只需要在哪里就需要该值。
因此,这就是这样...
$ product_id是唯一ID的变量。
然后,如果您有大量产品可以在产品ID数组上添加循环,并且它将在您的保存中制作新行,或者在产品首先找到产品时进行更新。
Why are you sending an array at a firstornew? This is basically a string that you are building an array with in the eloquent. Inserting an array will not work. Really the product_id should be a unique so you only need that value in your where.
So it would be something like this...
$product_id being the variable of the unique id.
Then if you have tons of products to add just loop over the array of product ids and it will either make a new row at your save or update the product when it finds it first.