update laravel query code example

Example 1: how to insert multiple data at a time with create method in laravel

$data = [
    ['user_id'=>'Coder 1', 'subject_id'=> 4096],
    ['user_id'=>'Coder 2', 'subject_id'=> 2048],
    //...
];

Model::insert($data); // Eloquent approach
DB::table('table')->insert($data); // Query Builder approach

Example 2: update column value laravel

Page::where('id', $id)->update(array('image' => 'asdasd'));

Example 3: laravel update from query

$affected = DB::table('users')
              ->where('id', 1)
              ->update(['votes' => 1]);

Example 4: wherein laravel

DB::table('user')->whereIn('id', [100,200])->get();

Example 5: laravel db::query update

DB::table('user')->where('email', $userEmail)->update(array('member_type' => $plan));

Example 6: update query in laravel eloquent

$data = DB::table('cart')
                ->where('crt_id', $id)
               ->update(['crt_status' =>'0']);

Tags:

Misc Example