Skeldar
Skeldar

Reputation: 153

How to use agregate on update in laravel?

I would like to change value in table dynamically i mean if value in column is 0 set 1 and reverse when 1 set 0. I noticed that when i use mysql query:

UPDATE table set column = ABS(column-1)

its working but how to implement that into Laravel eloquent (update)?

Upvotes: 0

Views: 47

Answers (1)

Jerodev
Jerodev

Reputation: 33196

You can use DB::raw() to add raw database expressions anywhere in your query.

DB::table('table')->update(['column' => DB::raw('ABS(column-1)')]);

Upvotes: 1

Related Questions