Update last created record in Laravel

Updated at 23-Jul-2021, By samar

Update last created record in Laravel

With this article, we’ll look at some examples of how to address the "Update last created record in Laravel" problem.

You can easily update the last created record in Laravel. Sometimes you have to save the record and after that you have to do some other task and get some value from it and insert the value in same record which you created.
  • Update created record after create() method in laravel

    //Import product class 
    $product = Product::create(['name'=>$request->name]);
    $updateProduct = Product::where('id', $product->id)->update(['inventory_id'=>1]);
    

    Create() method in laravel return model object after the record is created. After that, you can update the product using the where condition on that project model.

Back to code snippet queries related laravel