Vincent's blog

Upsert

I recently discovered upserts while importing a large amount of data into a Laravel application. We can use upsert to execute multiple "upserts" in a single query, improving performance.

Flight::upsert([
    ['departure' => 'Stockholm', 'destination' => 'Göteborg', 'price' => 50],
    ['departure' => 'Malmö', 'destination' => 'Göteborg', 'price' => 150]
], ['departure', 'destination'], ['price']);

#laravel #php