V
V
vlog2022-01-12 21:40:19
Laravel
vlog, 2022-01-12 21:40:19

How to abort saving a Laravel model instance?

The situation is the following. I deal with money transactions. If the server has not responded to the payment system's request, it repeats it.
Each transaction is recorded in the database.

Now I want to make sure that transactions are not re-recorded if the server gives an incorrect answer.

To do this, I take the Id that comes with the transaction and write it down in the corresponding field of the table.

Essence of the question. To check if a transaction with the same Id has already been created, I listen to the creating event. How can I interrupt the creation of a record from an event? Just delete the created object? I did not find such a method in the documentation, but, most likely, I just searched badly ...

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
vism, 2022-01-12
@vlog

r
 e
  t
   u
    r
     n

     f
    a
   l
  s
 e
;

A
Alex Wells, 2022-01-12
@Alex_Wells

https://laravel.com/docs/8.x/database#database-tra...

T
Timur Maslov, 2022-01-14
@tmaslov22

At the database level, add a unique constraint to the Id field. Additionally, at the code level, before creating a transaction, check through the sql query exist.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question