Update Query Use in Laravel

Update Query use in Laravel 5.8, Update Query in Laravel by Model,Update Query in Laravel 5.0 by Model,Update Query in Laravel 5.1 by Model,Update Query in Laravel 5.2 by Model,Update Query in Laravel 5.3 by Model,Update Query in Laravel 5.4 by Model,Update Query in Laravel 5.5 by Model,Update Query in Laravel 5.6 by Model,Update Query in Laravel 5.7 by Model

In the laravel how values ​​are updated and you can easily read and teach it. The query of the update in laravel is written in this way.

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

You can update the data from this query, using the method that is used without updating the data without creating the model. But if you want to update the data after creating the model then the query of the update in laravel is written in such a way that you have to type the model name.

Update Query use in Laravel by Model

 

Modelname::where('id', 1)->update([
'tablename_1' => 'value1'
]);
User::where('id', 1)->update([
'email' => 'rahul@gmail.com'
]);

 

Update Query use in Laravel by Query Builder

$users = table('users')->where('id', 1)->update([
'tablename_1' => 'value1'
]);
$users = table('users')->where('id', 1)->update([
'email' => 'rahul@gmail.com'
]);