updateOrCreate() not updating but adding new - php

Trying to update inserted data. But it's not quite working. If the data in the $variable changed then updateOrCreate method is just creating a new row. But it's supposed to be update the existed column?
$placeItems = [
"website_id" => self::WEBSITE_ID,
"url" => $place,
"place_name" => $title,
"image" => $image,
"description" => "I am changing here",
];
Place::updateOrCreate($placeItems);
I changed the description column. And use updateOrCreate, but it's not update the id of description in. Insert it as new. The way i am using updateOrCreate is wrong?
UPDATED
I tried a way as mentioned in the answer below and test it.
$description = "new data";
$placeItems = [
"website_id" => self::WEBSITE_ID,
"url" => $place,
"place_name" => $title,
"image" => $image,
"description" => "old data",
];
Place::updateOrCreate([
"website_id" => self::WEBSITE_ID,
"url" => $place,
"place_name" => $title,
"image" => $image,
"description" => $description,
], $placeItems);
But it still inserting as new column. not updating the ID of description in.

In your case you should specify parameters for updatedOrCreate.
The first parameter indicates the conditions for a match and second parameter specify which fields to update.
Place::updateOrCreate([ "website_id"=> self::WEBSITE_ID], [
"url" => $place,
"place_name" => $title,
"image" => $image,
"description" => $description]);
Read documentation here

Related

Zammad API: Create ticket with tag

For those who don't want to read the whole question:
I'm looking for the index in the API-Request (Zammad) to set a tag while creating a ticket.
Details:
I'm using PHP to make an API-Request to my server where Zammad is installed. The following shows the data i sent via curl:
json_encode([
"title" => $title,
"group_id" => 2,
"priority_id" => 2,
"category" => 'Some Category',
"state_id" => 1,
"type" => "Some Type",
"customer" => $userID,
"article" => [
"body" => $htmlBody,
"type" => "note",
"content_type" => "text/html",
],
"tag_list" => [ // <-- The question is about this segment
"The tag i want to add",
],
]);
After converting the data to JSON, im sending it via POST to http://<myServerIP>/api/v1/tickets
What I've tried so far:
I tried guessing the index of the tag at which i failed.
The first full example is shown above.
Secondly:
...
"tag_id" => 9, // I've check its the actual ID of the tag i want to add
And Finally:
...
"tag" => "The tag i want to add",
Needless to say that i didn't succeed. Sometimes i get an error id (im assuming its because the index doesn't exist [who would have thought that? :)]), sometimes i get nothing and Zammad just creates the ticket without the tag. What do i mean when i say sometimes? I refer my tries specified above.
What I've also tried:
Searching for some answer on the web. The thing that comes close to what i want is this. But i would rather create the ticket with the tag instead of making another request just to add the tag.
I've looked inside the code, its written in ruby. The index is 'tags' and needs to be sperated by ,.
Basicly:
json_encode([
"title" => $title,
"group_id" => 2,
"priority_id" => 2,
"category" => 'Some Category',
"state_id" => 1,
"type" => "Some Type",
"customer" => $userID,
"article" => [
"body" => $htmlBody,
"type" => "note",
"content_type" => "text/html",
],
"tags" => "tag1,tag2,tag3", // or simply "tags" => "tag1"
]);
It might help someone in the future ...

Fill custom CRM fields in Bitrix via REST API

I have the need to fill custom fields in Bitrix24 CRM via REST API.
When it comes to working on standard fields (like TITLE, TEL, etc) it works, but if I try to valorize a custom field by putting it's property name in the request the endpoint simply ignores it.
Here you have a snippet:
$company = CRest::call(
'crm.company.add',
[
'fields' => [
"TITLE" => "Company 1"
, "COMPANY_TYPE" => "Customer"
, "CURRENCY_ID" => 'EUR'
, "REVENUE" => "123000"
, "ADDRESS" => "st. some address"
, "ADDRESS_CITY" => "some city"
, "ADDRESS_POSTAL_CODE" => "12345"
, "ADDRESS_PROVINCE" => "some province"
, "PHONE" => [
["VALUE" => "1230000000", "VALUE_TYPE" => "WORK"]
,["VALUE" => "1234000000", "VALUE_TYPE" => "FAX"]
]
, "EMAIL" => [ ["VALUE" => "me#company1.com", "VALUE_TYPE" => "WORK"] ]
, "INDUSTRY" => "MANUFACTURING"
, "CUSTOM_FIELD" => "Hey I'm not a standard field and I'm going to be ignored"
]
]
);
Did anyone have the same need? How can I solve it?
I found the solution.
Simply write the Field ID instead of the Field Name. The Field ID looks like "UF_CRM_5AERER454DD4". By putting this as key and the value after " => " the property gets valorized.

MongoDB PHP function InsertMany() is not working

I am facing problem in MongoDB with PHP, I am using MongoDB InsertMany() function with the below code--
$document = array(array(
"title" => $_POST['title'],
"description" => $_POST['description'],
"likes" => $_POST['likes'],
"writenby" => $_POST['writtenby'],
"url" => $_POST['urllnk'],
), array("label1"=>"1","label2"=>"2"), array("label3"=>"3","label4"=>"4"));
$collection->insertMany($document);
I tried to insert data but the code is not working.
Thanks

Add Organisation & Contact to Insightly and automatically link them

I am using a PHP library (https://github.com/Insightly/insightly-php) with great success for the Insightly API. More information on the Insightly API can be found here: https://api.insight.ly/v2.2/Help
My goal is to have an organisation and a contact added to Insightly on a form submission and to then link the two together. I can add the organisation and the contact without any issues but I am having troubles linking the two afterwards. When I add in the code to link the two it is only adding the organisation and not the contact.
Please view my code below:
$organization = $i->addOrganization($newOrganization);
$getOrganizationID = $i->getOrganization($company);
$id = json_decode($getOrganizationID, true);
$newContact = (object)array(
"FIRST_NAME" => $first_name,
"LAST_NAME" => $last_name,
"CONTACTINFOS" => array(
(object)array(
"TYPE" => "EMAIL",
"LABEL" => "WORK",
"DETAIL" => $email,
),
(object)array(
"TYPE" => "PHONE",
"LABEL" => "WORK",
"DETAIL" => $phone,
)
),
"LINKS" => array(
(object)array(
"ORGANISATION_ID" => $id[0]['ORGANISATION_ID'],
)
),
);
$contact = $i->addContact($newContact);
I had a faulty link in the getOrganization() function and have since fixed it.

DocuSign REST API (PHP) - pre-fill custom tags

I am working on project in which I need to use DocuSign API (PHP). This is my first experience with DocuSign and I successfully made template in DocuSign Console with roleName = signer. There I also made Custom Text Tags: address, city, state and phone and drag them to the desired location in my template. I want there to put my customer (signer) information from project database.
From my project I successfully made connection with DocuSign via PHP API and receive Embedded Singing View URL which opens my template where the user can sign document without problem.
But... all my custom text tags are empty and signer can type into them. I need to pre-fill them with signer personal data which is coming from database. I triple check custom tag label spelling, upper/lower case in my DocuSign Console and in my code as well as roleName->tagLabel relation. My PHP code is below.
Can someone, please, tell me what I am doing wrong?
I lost two days on it.
$data = array(
"accountId" => $accountId,
"emailSubject" => $this->_emailSubject,
"templateId" => $templateId,
"templateRoles" => array(
array(
"email" => $email,
"name" => $recipientName,
"clientUserId" => $clientUserId,
"roleName" => "signer",
"customFields" => array(
"textCustomFields" => array (
array (
"name" => "address",
"value" => "Address from DB",
"show" => "true",
),
array (
"name" => "city",
"value" => "City from DB",
"show" => "true",
),
array (
"name" => "state",
"value" => "State from DB",
"show" => "true",
),
array (
"name" => "phone",
"value" => "Phone from DB",
"show" => "true",
),
),
),
),
),
"status" => "sent"
);
You need to use the textTabs type in your JSON, not customFields which is used for something else. For instance, if you drag a Data Field from the UI onto the document and give it name address, to pre-fill that field you would need to reference it's tabLabel and value fields like this:
"roleName" => "signer",
"tabs" => array(
"textTabs" => array(
array(
"tabLabel"=> "address",
"value" => "123 Main St."
)
)
)

Categories