How to update record after save method in Laravel

Updated at 23-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