Laravel从数据库中减去

时间:2014-06-12 02:38:16

标签: php laravel eloquent subtraction

我试图使用雄辩的模型从数据库中减去一个值,而我似乎无法让它发挥作用。

以下是我现在所拥有的:

     public function store()
{
    $sku = Input::get('sku');
    $quantitysold = Input::get('quantitysold');

    $inventory = Inventory::where('sku', $sku)->decrement('sku', $quantitysold);
    $inventory->save();


    $transaction = new Transaction;
    $transaction->sku = $sku;
    $transaction->quantitysold = $quantitysold;
    $transaction->save();



    return 'Item has been saved';
}

当我尝试修补时,我得到以下内容:

    PHP Fatal error:  Call to a member function save() on a non-object

1 个答案:

答案 0 :(得分:0)

使用save后,请勿致电decrement

decrement方法本身runs the query