Update last created record in Laravel

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.

Answers 1
  • 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