I am using laravel 5.8 with mysql InnoDb engine. I have the following code:
DB::transaction(function () {
$temp = new Permission();
$temp->displayName = 'first1';
$temp->uniqueName = 'first1';
$temp->save();
try {
DB::transaction(function () {
$temp2 = new Permission();
$temp2->displayName = 'first2';
$temp2->uniqueName = 'first2';
$temp2->save();
});
} catch (\Exception $ex) {}
throw new \Exception();
});
I expect the permission first2 to be inserted in the database and the permission first1 will not be inserted since there is an exception in the outer transaction.
But what happens is: both permission first2 and permission first1 are not inserted. why?
by the way, I have tested the following:
and it works fine (since the exception in the inner transaction). can someone explain what happens?
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/38xQc8B
via IFTTT
Aucun commentaire:
Enregistrer un commentaire