2017-03-07 16 views
1

我想回路數據插入到與laravel數據庫,但它返回以下錯誤:我想回路數據插入到數據庫中,但它給了一個錯誤

ErrorException in Grammar.php line 118: Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, string given, called in C:\xampp\htdocs\laravel\App\vendor\laravel\framework\src\Illuminate\Database\Query\Grammars\Grammar.php on line 678 and defined

查看:

<input name="product_id[]" type="hidden" class="rid" value="13"> 
<input type="hidden" name="product_name[]" value="Popins"><input type="hidden" name="product_code[]" value="2323"> 
<input name="unit_price[]" type="hidden" value="170"> 
<input name="quantity[]" type="text" value="2" id="" > 

控制器

for($i=0; $i<count($product_name);$i++){ 
    $newSafety = new saleItems; 
    $newSafety->product_id = $request->unit_price; 
    $newSafety->sale_id = $request->unit_price; 
    $newSafety->product_code = $request->product_code; 
    $newSafety->product_name = $request->product_name; 
    $newSafety->quantity = $request->quantity; 
    $newSafety->unit_price = $request->unit_price; 
    $newSafety->gross_total= $request->unit_price; 
    $newSafety->save(); 
} 
+0

哪個Laravel的版本您使用的?請不要TAG SPAM – RiggsFolly

+1

哪些是** 678 **在** 12行**中**您已經向我們顯示 – RiggsFolly

+0

@RiggsFolly使用的是laravel 5.2和Grammar.php,您所說的768行是laravel文件。我沒有做到 –

回答

0

看起來每個通過請求傳遞的輸入都是數組,而您試圖將它們分配給$ newSafety對象的非數組屬性。

試試這個:

for($i=0; $i<count($product_name);$i++){ 
    $newSafety = new saleItems; 
    $newSafety->product_id = $request->unit_price[i]; 
    $newSafety->sale_id = $request->unit_price[i]; 
    $newSafety->product_code = $request->product_code[i]; 
    $newSafety->product_name = $request->product_name[i]; 
    $newSafety->quantity = $request->quantity[i]; 
    $newSafety->unit_price = $request->unit_price[i]; 
    $newSafety->gross_total= $request->unit_price[i]; 
    $newSafety->save(); 

}

相關問題