invoiceninja / sdk-php

PHP wrapper for Invoice Ninja's REST API
https://www.invoiceninja.com
83 stars 42 forks source link

Add clients contact with SDK OK, but what about edit? #65

Closed mgip closed 3 years ago

mgip commented 3 years ago

I try to complement the sdk with edit the contact of specific clients, but nothing, i share the code:

` $client = Client::find($clientExiste[0]->id);

        $client->name = $dataEnviar['company_name'];
        $client->display_name = $dataEnviar['company_display_name'];
        $client->address1 = $dataEnviar['company_address1'];
        $client->address2 = $dataEnviar['company_address2'];
        $client->city = $dataEnviar['company_city'];
        $client->state = $dataEnviar['company_state'];
        $client->postal_code = $dataEnviar['company_postal_code'];
        $client->country_id = $dataEnviar['company_country_id'];
        $client->work_phone = $dataEnviar['company_work_phone'];
        $client->vat_number = $dataEnviar['company_vat_number'];
        $client->id_number = $dataEnviar['company_id_number'];
        $client->contacts = array(
            'id' => $dataEnviar['contacto_id'],
            'first_name' => $dataEnviar['contacto_first_name'],
            'last_name' => $dataEnviar['contacto_last_name'],
            'email' => $dataEnviar['contacto_email'],
            'phone' => $dataEnviar['contacto_phone']
        );

        $client->save();`

What am i do wrong?

Thanks

hillelcoren commented 3 years ago

It looks you're overwriting the contacts array rather than updating the existing contact.

Note: please use Slack for the forum for support.

mgip commented 3 years ago

Hi guys, the problem was that the other side (Laravel) expect a multidimentional array. My solution was:

$client->contacts[] = array(

    'id' => $client->contacts[0]->id,

    'first_name' => $dataEnviar['contacto_first_name'],

    'last_name' => $dataEnviar['contacto_last_name'],

    'email' => $dataEnviar['contacto_email'],

    'phone' => $dataEnviar['contacto_phone']

);

I hope it helps someone.

We'll see you on Slack. Thanks @hillelcoren for the information.