How to update record after save method in Laravel

Created at 24-Jul-2021 , By samar

How to update record after save method in Laravel

We’ll attempt to use programming in this lesson to solve the "How to update record after save method in Laravel" puzzle.

You can update the record which you recently saved in your database using save method in Laravel. You can get the id of recently saved record and after that you can use update method with where condition to update the record.
  • Update record after save method in Laravel

    // Import project model in controller class
    $product = new Product;
    $product->name = $request->name;
    $product->save();
    Product::where('id', $product->id)->update(['inventory_id'=>1]);
    

    Using this code snippet you can update the recently added record. You can use the id of recently created record after the save method and after that you can call update method on this record using where condition in laravel.

Back to code snippet queries related laravel

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.