Support the ongoing development of Laravel.io →
Database Eloquent

Hi,

I currently creating this somewhat complicated abstraction layer. is it possible to cancel or rollback save of model if for ex. i have 2 models

class User extends Eloquent {
//column name, address, bday

   public function hobbies()
   {
    return $this->has_many('Hobbies');
   }
}

Class Hobbies extends Eloquent
{
   //column name, level, type   
}

Usually to save this, you will save the User then, save the Hobbies

  • when user is save and on save of hobbies an error occured then how can I rollback the transaction for the user

  • the main thing is I may have a master model and many detail model what is the best approach of saving this onebyone or by batch and roll it back if DB error or any validation occur occured.

  • Is thier a way I can save the User Model and the has_many Models in one go, and rollback or dont save on any error?

Please help

Thanks

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

nickaceph nickaceph Joined 18 Mar 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.