Laravel 6 Update Increment column

Today, We want to share with you Laravel 6 Update Increment column.In this post we will show you laravel 6 update timestamp, hear for increment by update field in laravel we will give you demo and example for implement.In this post, we will learn about How to increment and update column in one eloquent query with an example.

Laravel 6 Update Increment column

There are the Following The simple About How to increment a column using Eloquent Model in Laravel 6 Full Information With Example and source code.

As I will cover this Post with live Working example to develop increment and decrement value in laravel 6, so the laravel call to a member function increment() on integer is used for this example is following below.

MySQL Database Table fields increment in laravel 6

Movie::where('movie_id', $movie->id)
->update([
  'pageview'=> DB::raw('pageview+1'), 
  'last_pageview_increased_at' => Carbon::now()
]);

additional columns to update during the operation:

Movie::where('movie_id', $movie->id)
->increment('pageview', 1, ['last_pageview_increased_at' => Carbon::now()]);

Increment columns in laravel 6

using update() methods

DB::table('players')
   ->where('status', 1)
   ->update([
       'runs' => DB::raw('runs + 2'),
       'fifty' => DB::raw('fifty + 10'),
       'sadi' => DB::raw('sadi + 13'),
       'bevdi' => DB::raw('bevdi + 5'),
   ]);

how to use increment() and decrement() in laravel

$query = DB::table('movies')
  ->where('movie_id',$movie->id)                                     
  ->where('smonth','=',$date_exploded[1])
  ->where('syear','=',$date_exploded[2]);

$query->increment('pageview_a');
$query->decrement('pageview_p');

increment or decrement a column value in laravel?

plus 1 By Using increment()

public function pageviewIncrement($id = 1)
{
	Movie::where('id',$id)->increment('pageview',1);
}

plus 1 By Using update()

public function pageviewIncrementWithUpdate($id = 1)
{
	Movie::where('id',$id)->update(['pageview' => DB::raw('pageview+1')]);;
}

minus 1 By Using decrement()

public function pageviewDecrement($id = 1)
{
	Movie::where('id',$id)->decrement('pageview',1);
}

minus 1 By Using update()

public function pageviewDecrementWithUpdate($id = 1)
{
	Movie::where('id',$id)->update(['pageview' => DB::raw('pageview-1')]);;
}

Laravel 6 Eloquent Incrementing columns

Eloquent: incrementing columns without update() function

when Update the row

$customer = Movie::find($movie_id);
$pageview = $customer->pageview + 1;
$customer->update(['pageview' => $pageview]);

using increment

Movie::find($movie_id)->increment('pageview');

using increment

Movie::find($movie_id)->increment('pageview', 50);

using decrement

Movie::find($movie_id)->decrement('pageview', 50);

Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about laravel increment column by 1.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1.   Autocomplete Textbox using jQuery, PHP and MySQLi
  2.   How to Declare Global Variable in Laravel 6?
  3.   jQuery Get Dropdownlist Selected Value Onchange Event
  4.   Laravel 5/6/7 Carbon date format Example
  5.   PHP Get Folder Path From File Path Examples
  6.   laravel print last query | Executed | Sql | php | tutorials
  7.   Introduction To Math Class in C# ASP.NET
  8.   Group By Preserve Key using Laravel Collection
  9.   Laravel Return Ajax JSON Response Example
  10.   Laravel 6 get last Insert id from query builder