php laravel update 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);
DB::table('table')->insert($data);
Example 2: update column value laravel
Page::where('id', $id)->update(array('image' => 'asdasd'));
Example 3: laravel updateOrCreate
$flight = App\Flight::updateOrCreate(
['departure' => 'Oakland', 'destination' => 'San Diego'],
['price' => 99, 'discounted' => 1]
);
Example 4: laravel update from query
$affected = DB::table('users')
->where('id', 1)
->update(['votes' => 1]);
Example 5: laravel create model
php artisan make:model Flight
php artisan make:model Flight --migration
php artisan make:model Flight -m
Example 6: laravel not in query
DB::table(..)->select(..)->whereNotIn('book_price', [100,200])->get();