Skip to content

Conversation

@johnbirchevans
Copy link

@johnbirchevans johnbirchevans commented Nov 8, 2023

Upsert has been added to Laravel since v8.x. A Laravel upsert expects 2 parameters to be passed, which are usually arrays

Laravel Upsert Documentation

Flight::upsert([
    ['departure' => 'Oakland', 'destination' => 'San Diego', 'price' => 99],
    ['departure' => 'Chicago', 'destination' => 'New York', 'price' => 150]
], ['departure', 'destination'], ['price']);

If the array of values is not nested in an array then the builder will automatically wrap the value in an array

Laravel Upsert Method

if (! is_array(reset($values))) {
            $values = [$values];
        }

This means that the value passed to the datastore SDK is invalid and will fail, This fix will allow the upsert to behave as expected.

@arafatkn
Copy link
Collaborator

@johnbirchevans Thanks for the PR.
here, you have used only the first item from the passed array. Can you please update the PR so that upsert can support both single and batch upsert? (same as others)
Reference: https://cloud.google.com/datastore/docs/samples/datastore-batch-upsert#datastore_batch_upsert-php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants