mercredi 12 février 2020

Rollback previous deleted rows if any failure occurs in laravel

i want to delete all records in this and if any table value is not deleted i want to roll back all previous deleted rows in this.Here is my code

 DB::beginTransaction();
    try {
        $customers = Customer::findOrFail($id);
        $customers->delete();
        $user = User::where('name','=',$customers->user_id)->first();
        $user->delete();
        DB::commit();
    } catch (\Exception $ex) {
        DB::rollback();
        return response()->json(['error' => $ex->getMessage()], 500);
    }

in this if customers got deleted and while deleting user if any problem occurs i want to rollback the previously deleted customers data.But here its not working.The customers data is deleting and not restoring it



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/38mGt4H
via IFTTT

Aucun commentaire:

Enregistrer un commentaire