Laravel:无法在Laravel Eloquent

时间:2017-02-11 05:08:57

标签: php laravel eloquent laravel-5.3

我正在尝试使用laravel eloquent使用列的当前值加上新值加上新值,查询执行成功但查询不在数据库中插入任何记录。

PurchaseController.php:

$insertPurchase = [];
$insertPurchase['godown_id'] = Auth::user()->id;
$insertPurchase['bill_id'] = $bill_id;
if ($value['exist'] == 0) {
    $this->insertProductIntoRetailProduct($value);
}
$insertPurchase['item_id'] = $value['item_id'];
$insertPurchase['mrp'] = $value['mrp'];
$parsed = Carbon::parse($value['expiry_date']);
$insertPurchase['expiry'] = $parsed->format('Y-m-d');
$insertPurchase['sale_price'] = $value['sale_price'];
$insertPurchase['purchase_price'] = $value['purchase_price'];
$insertPurchase['qty'] = $value['qty'];
$insertPurchase['free_barcode'] = $value['free_barcode'];
$insertPurchase['free_name'] = $value['free_name'];
$insertPurchase['free_qty'] = $value['free_qty'];
$insertPurchase['product_vat'] = (isset($value['product_vat'])) ? $value['product_vat'] : 0;
$insertPurchase['sku'] = $value['sku'];
$insertPurchase['vat_status'] = $billDetails['vat'];
$PurchaseList = new PL($insertPurchase);
$PurchaseList->save();
unset($insertPurchase['qty']);
$GodownStock = GodownStock::firstOrNew(['item_id' => $value['item_id']])
    ->increment('qty', $value['qty'], $insertPurchase);

型号:PurchaseList.php:

public function increment($column, $amount = 1, array $extra = array()){

    $wrapper = $this->grammar->wrap($column);

    $columns = array_merge(array($column => $this->raw("$wrapped + $amount")), $extra);

    return $this->update($columns);
}

如果item已经存在,我只想增加数量,否则只需插入新行。 任何人都可以告诉我我的代码有什么问题吗?

0 个答案:

没有答案