laravel where update code example

Example 1: create or update in laaravel

//if there is id => 1 for user role , update this and if there is not 
//id => 1 create it and insert some data for it
 $data = $request->all();
   UserRule::updateOrCreate(
            ['id' => 1],
            $data
        );

Example 2: laravel update from query

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

Example 3: update query in laravel eloquent

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

Example 4: update laravel

use App\Models\Flight;

$flight = Flight::find(1);

$flight->name = 'Paris to London';

$flight->save();