My idea is to create a function in which I will pass an array as a parameter with the format
array("c_digo"=>$cod,"nome"=>$nomecompleto)
And create a loop with this array so that it creates the same fields_attributes in this string below. I'm currently creating in the hand, I want to do dynamically with the array. I hope you can explain, any questions you may ask me
$queryObj = [
'query' =>
'mutation {
createCard(
input: {
pipe_id: '.$pipeid.'
fields_attributes: [{
field_id: "c_digo",
field_value: "'.$cod.'"
}{
field_id: "nome",
field_value: "'.$nomecompleto.'"
} {
field_id: "email",
field_value: "'.$email.'"
} {
field_id: "telefone",
field_value: "'.$telefone.'"
}]
}
) {
card {
id
}
}
}'
];
$query = json_encode($queryObj);
Desired function
public function createcard($array){
// exemplo de array recebido: array("c_digo"=>$cod,"nome"=>$nomecompleto)
// Create query object
// deve criar esse queryobj já com os campos vindos do array ( atualmente ele ta preenchido manualmente)
$queryObj = [
'query' =>
'mutation {
createCard(
input: {
pipe_id: '.$pipeid.'
fields_attributes: [{
field_id: "c_digo",
field_value: "'.$cod.'"
}{
field_id: "nome",
field_value: "'.$nomecompleto.'"
}]
}
) {
card {
id
}
}
}'
];
$query = json_encode($queryObj);
// deve retornar esta variavel $query
}