Update last created record in Laravel

Created at 24-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

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.