1
My idea is to create a function where 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 am currently creating at hand, I want to do dynamically with the array. I hope you can explain, any doubt 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);
Intended 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
}
compound arrays?
– Wees Smith
Yes, it was not very clear no. Why not give an input example that the function would receive and what output it should generate? Maybe it’ll make it easier to understand.
– Woss
@Andersoncarloswoss added
– Igor Oliveira
Dude, I don’t get it yet, you want to create this array inside the loop?
– Wees Smith
I want the array to become this string, if the array has 3 elements I will have 3 fields_attributes and so on
– Igor Oliveira