Laravel 6 FirstorCreate Increment and update column using Eloquent

Today, We want to share with you Laravel 6 FirstorCreate Increment and update column using Eloquent.In this post we will show you wordpress plugin require another plugin, hear for eloquent update column laravel 6 we will give you demo and example for implement.In this post, we will learn about laravel updateorcreate increment with an example.

Laravel 6 FirstorCreate Increment and update column using Eloquent

There are the Following The simple About Laravel How to increment only when its a new insert? Full Information With Example and source code.

As I will cover this Post with live Working example to develop Eloquent: incrementing columns without update() function, so the Laravel eloquent update column value by adding new value is used for this example is following below.

READ :  jQuery Ajax Live Editable Table Records using PHP MySQLi

Example 1: Laravel, Update Query and FirstorCreate Method

		$product_id = 12058;
		$url = "https://www.modi.com";
		$desc = "Nice and Good Producs for Web";

        Products::firstOrCreate(['product_id' => $product_id,'ext_time'=>date("Y-m-d H:00:00"),'name'=> addslashes($product_name)],['up_votes'=>0,'web_domain'=>$url,'desc'=>$desc])->increment('up_votes');

very useful Laravel Methods firstOrCreate() to try and find a row, and create it if it doesn’t exist.

$tamilrokers = App\Tamil::firstOrCreate(['name' => 'Tamil 10']);
 
$tamilrokers = App\Tamil::firstOrCreate(
    ['name' => 'Tamil 10'], ['pageview' => 1]
);
 
$tamilrokers = App\Tamil::firstOrNew(['name' => 'Tamil 10']);
 
$tamilrokers = App\Tamil::firstOrNew(
    ['name' => 'Tamil 10'], ['pageview' => 1]
);

E-junkie: Sell digital downloads online

E-junkie Provides a Copy-paste buy-now, and cart buttons for selling downloads, codes and tangible products on any website, blog, social media, email and messenger!

Also see:

  1. The Top 10+ Best Webinar Software Platforms For 2020-2021
  2. Build Your Future Godaddy Careers And Jobs
  3. Introduction To Web Hosting Services

function downVote($id)
{
      DB::table('products')
          ->where('id', $id)
          ->decrement('upVotes', 1)
          ->increment('downVotes', 1);
}

How to increment and update column in one eloquent query

$user = User::find($user->user_id);
if($user){
    $user->increment('total_members',1);
}else{
    $user = new User();
    $user->total_members = 1;
    // Inert new user here with all related data
    $user->save(); 
}
return $user->id;

Creating and Update Laravel 6 Eloquent

$student = Student::firstOrNew(array('stud_name' => Input::get('stud_name')));
$student->age = Input::get('age');
$student->save();

useing updateOrCreate

$student = App\Student::updateOrCreate(
    ['lastname' => 'chovatiya', 'destination' => 'surat'],
    ['age' => 38]
); 

Web Programming Tutorials Example with Demo

Read :

READ :  Laravel Has Many Through Eloquent Relationship Example

Summary

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

I hope you get an idea about laravel 6 update method.
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.