Reputation: 4161
I want to update two column of mysql table,
column1
decrement with some value and column2
multiplication with some value,
I have done about decrement like this from here
$stock_obj->decrement('quantity_on_hand', $product_data["quantity"], array(
'total_quantity_on_hand' => 'quantity_on_hand' * some_other_value
));
Here decrement working but how can i do multiplication?
I have that solution in CI(CodeIgniter) but don't know how to does it in laravel any help would be appreciated...
$this->db->set("quantity_on_hand", "quantity_on_hand-" . ($product_data["quantity"] ? $product_data["quantity"] : 0), FALSE);
$this->db->set("total_quantity_on_hand", "quantity_on_hand*" . ($product_data['product_packing_value'] ? $product_data['product_packing_value'] : 1), FALSE);
$this->db->where("id", $warehouse_transfer_product_data['stock_id'])->update("stock");
Upvotes: 1
Views: 3831
Reputation: 40909
The following should do the trick:
DB::table('your_table')
->where('some_column', $someValue)
->update(array(
'column1' => DB::raw('column1 * 2'),
'column2' => DB::raw('column2 - 1'),
));
Upvotes: 6