我现在只是想知道为什么这个与数据库交互的特定表会返回一个错误,就像上面的主题一样,实际上我只是使用了与其他表相同的机制。我正在参考我的表“库存”。我的存储方法只是简单地返回上面主题中陈述的错误,我检查了控制器和我的模型中的所有参数,似乎没有错误。有人可以帮助我发现这里的错误。请帮忙。这是我的代码。
InventoryController.php
public function store( Request $request ){
$prod_ids = $request['product_ids'];
$purchase_order_ids = $request['purchase_order_ids'];
$purchase_ids = $request['purchase_ids'];
$quantity = $request['purchaseQuantity'];
for($i = 0; $i < count($prod_ids); $i++){
Inventory::create([
'product_id' => $prod_ids[$i],
'purchase_order_id' => $purchase_order_ids[$i],
'purchase_id' => $purchase_ids[$i],
'quantity' => $quantity[$i]
]);
}
return json_encode(array('notify' => "Success"));
}
我的模特=&gt; Inventory.php
<?php
namespace App\Inventory;
use Illuminate\Database\Eloquent\Model;
class Inventory extends Model
{
protected $fillable =
['product_id','purchase_order_id','purchase_id','quantity'];
}
我的Javascript:
$("#purchase_toInventoryID").click(function(e){
e.preventDefault();
var array_prodID = <?php echo json_encode(isset($array_prodID) ? $array_prodID : 0); ?>;
var array_poID = <?php echo json_encode(isset($array_poID) ? $array_poID : 0); ?>;
var array_purchaseID = <?php echo json_encode(isset($array_purchaseID) ? $array_purchaseID : 0); ?>;
var array_purchaseQuantity = <?php echo json_encode(isset($array_purchaseQuantity) ? $array_purchaseQuantity : 0); ?>;
$.post("{{ url('saveToInventory') }}", {
'product_ids': array_prodID,
'purchase_order_ids': array_poID,
'purchase_ids':array_purchaseID,
'purchaseQuantity': array_purchaseQuantity
}, function(data){
if(data.notify == "Success"){
console.log(data.notify);
}else{
console.log(data.notify);
}
}, 'json');
});
我的routes.php
Route::post('saveToInventory', 'Inventory\InventoryController@store');