What is the best way to pass data from 2 tables to a json?

-2

I have 2 tables, being CustomerCpf and CustomerCnpj . They have no connection to each other.

What would be the best way to pass the 2 tables on the same route with a json?

I had thought of something like this:

public function getAll(){
    $pessoaFisica = CustomerCpf::all();
    $pessoaJuridicaa = CustomerCnpj::all();

    $data = [
        "data" => [
            "fisica" => $pessoaFisica,
            "juridica" => $pessoaJuridicaa
        ]
    ];

    return response()->json([$data]);
}
    
asked by anonymous 18.12.2018 / 02:09

0 answers