Skip to content

Can i get only inserted data, but not an updated and inserted? #22

Answered by lapaliv
NikitaPoplavskiy asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @NikitaPoplavskiy.

Yes, sure. You can get it. There are two ways how to do it.

The first way:

app(BulkUpsert::class)
    ->onCreated(function(Collection $collection) {
        // Here you will get only inserted models
    })
    ->upsert(/* ... */);

The second way:

app(BulkUpsert::class)
    ->onSaved(function(Collection $collection) {
        $insertedRows = $collection->filter(
            fn(Model $model) => $model->wasRecentlyCreated
        );
    })
    ->upsert(/* ... */);

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by NikitaPoplavskiy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants