MySQL

Laravel raw SQL update query

MySQL

Laravel raw SQL update query

You can make use of db::raw when you want to test or use some arbitrary string inside the query builder.

To work with db::raw you have to make use of the DB facade class :

use Illuminate\Support\Facades\DB;

Example 1 :

DB::table('users')->where('id', '1')->update(['name' => 'Milind']);

Example 2 :

DB::update(DB::raw('UPDATE users SET name='Milind' WHERE id =1'));

Example 3 :

DB::statement(DB::raw('UPDATE users SET name='Milind' WHERE id =1'));