I have a problem with transactions in laravel. When I try to do this operation with the following code, the error appears on the screen as if I had no transaction.
\DB::transaction(function() use ($movement, $movementRows) {
$movement->save();
$movement->rows()->saveMany($movementRows);
});
and when I try to do it with the code below the first object is saved although the second one fails.
\DB::beginTransaction();
try {
$movement->save();
$movement->rows()->saveMany($movementRows);
\DB::commit();
$success = true;
} catch (\Exception $e) {
$success = false;
\DB::rollback();
}
if ($success) {
// the transaction worked ...
}