I am trying to update all records from table withing single eloquent query in Laravel 5.4
Currency::update(['default'=>0]);
I am expecting that this query will update all the records from a table, but this query isn't working. It is expecting where clause and I don't want to put any conditions using where clause, I just want to update all records in a table.
I am not getting any answer from laravel documentation.
MySQL has a safe update server mode which will not allow an update to happen unless the statement has a WHERE
clause involving the primary key. If your MySQL be running in this mode, then one way to spoof it would be to use WHERE id = id
, something like this:
DB::table('Currency')
->where('id', 'id')
->update(['default' => 0]);
If your MySQL server running SQL_SAFE_UPDATES mode you can use "where" like this. Or another "where clause" that includes all results.
Currency::where('id', '>', 0)->update(['default' => 0]);
Product::query()->update(['default' => 0, ]);
更新表中所有行的简单查询。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.