Return array inside json [closed]

1

I have the following function in Laravel/QueryBuilder

public function getEstudante(Request $request)
{
    $estudante = DB::table('estudantes_identificacao')
        ->leftJoin('estudantes_telefones','estudantes_telefones.estudantes_identificacao_id',
                   '=', 'estudantes_identificacao.id')    
    ->select(
        'estudantes_identificacao.id', 
        'estudantes_identificacao.nome_completo', 
    )
    ->where('estudantes_identificacao.id', '=', $request->estudante_id)
    ->get();

    return $estudante;
}

I need to return in the result the array of phones like this:

[
    {
        "id": 7597,
        "nome_completo": "MARIA MARIA",
        "telefones": [
            {
                "id_telefone": 60,
                "estudante_id_telefone": 7597,
                "ddd_id": 15,
                "telefone": "1234-5642",
                "diversos_operadora_id": null,
                "diversos_operadora_nome": null,
                "observacoes_telefone": "AASSSD"
            },
            {
                "id_telefone": 61,
                "estudante_id_telefone": 7597,
                "ddd_id": 31,
                "telefone": "9595-9595",
                "diversos_operadora_id": 3,
                "diversos_operadora_nome": "CLARO",
                "observacoes_telefone": ""
            }
        ]
    }
]

How to do it?

    
asked by anonymous 22.07.2018 / 15:45

1 answer

-2
<?php
//cria o array associativo
$idades = array("Jason"=>38, "Ada"=>35, "Delphino"=>26);

//converte o conteúdo do array associativo para uma string JSON
$json_str = json_encode($idades);

//imprime a string JSON
echo "$json_str";
?>

Result

{"Jason":38,"Ada":35,"Delphino":26}

Source: link

    
30.12.2018 / 00:35