I
I
Ilya Loopashko2021-06-17 06:07:10
Laravel
Ilya Loopashko, 2021-06-17 06:07:10

How to implement adding new data to the database?

Kind everyone. I have a controller that pulls data from one database (remote) to another (local). Where can I see or read how to implement the method: new data has appeared or changed in the remote database and only add them, there is a lot of data (more than 17 thousand records).

Controller:

DB::connection('db')->table('STAT.DOLJNOST')->select('kod', 'text')->orderBy('kod')->chunk(100, function ($positions){
            foreach ($positions as $position){
                Tag::create([
                    'title' => $post->text,
                    'id' => $post->kod
                    ]);
            }
        });

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ilya Loopashko, 2021-06-17
@deadloop

It turns out that everything can be solved easier, there is an updateOrInsert method. And he works.
Off. dock

K
Konstantin B., 2021-06-17
@Kostik_1993

Replication. Or use some mechanism to exchange messages between servers

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question