laravel 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: update column value laravel

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

Example 3: how to create model in laravel

php artisan make:model Flight

Example 4: laravel delete where

DB::table('users')->where('id', $id)->delete();

Example 5: laravel update


App\Models\Flight::where('active', 1)
          ->where('destination', 'San Diego')
          ->update(['delayed' => 1]);

Example 6: laravel update

$flight = App\Models\Flight::find(1);

$flight->name = 'New Flight Name';

$flight->save();

Tags: