Answer the question
In order to leave comments, you need to log in
How to know that the transaction goes through 3 times?
$i=0;
try
{
return DB::transaction(function () use ($p,$i)
{
$i++;
throw new \Exception();
$patientAnalyzes->delete();
return response()->json(['message' => 'p успешно удален'.$i], 200);
}, 3);
} catch (\Exception $exception)
{
return response()->json(['message' => 'Ошибка сервера повторите пожалуйста попытку'.$i], 500);
}
Answer the question
In order to leave comments, you need to log in
First, your catch can only work BEFORE all attempts are completed if the error is not a " concurrency error " as they are called in Laravel.
Secondly, if this happened, then it is still impossible to find out the number of the attempt, because as a result, just an exception is thrown without any parameters.
Run a transaction in a loop, catch errors and count attempts.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question