Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the upsert method to match the array passed from Laravel Builder #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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