samedi 27 février 2021

"updateOrCreate" method didn't rollback

I use laravel5 then I tried use "updateOrCreat". But it didn't rollback.

Please tell me how to rollback.

I tried following.

Pattern 1 : A data was inserted.

DB::beginTransaction();
Post::updateOrCreate(
    ['id' => '1']
   ,['name' => 'テスト']
);
DB::rollback();

Pettern 2 : A data wasn't inserted

DB::connection('post')->beginTransaction();
Post::updateOrCreate(
    ['id' => '1']
   ,['name' => 'テスト']
);
DB::connection('post')->rollback();

Pettern 3 : A data wasn't inserted

DB::connection('post')->beginTransaction();
Post::updateOrCreate(
    ['id' => '1']
   ,['name' => 'テスト']
);
DB::connection('post')->commit();

Pettern 4 : A data wasn't inserted

DB::beginTransaction(function() {;
    Post::updateOrCreate(
        ['id' => '1']
       ,['name' => 'テスト']
    );
});


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire