In Laravel 4, how do I convert the Model output to XML?

Asked

Viewed 97 times

1

In Laravel, how could I transform the following result below to an XML structure?

$usuarios = Usuario::with('nivel')->where(['status' => 1])->get()->toArray();

// Resultado:
[
   'usuarios' => [
       0 => [
                'id'   => 1,
                'nome' => 'Wallace',
                'nivel_id' => 4,
                'nivel'    => [
                    'id' => 4,
                    'nome' => 'Produção'
                ]


        ],
        1 => [
                'id'   => 2,
                'nome' => 'Wayne',
                'nivel_id' => 5,
                'nivel'    => [
                    'id' => 5,
                    'nome' => 'Recepção'
                ]


        ]
    ]
];

How could I use objects Model and Collection, to convert to XML?

Remark: THE Model is returning by the call of first, and Collection, by the call of get.

  • 1

    You can use package: https://github.com/SoapBox/laravel-formatter With it you can generate the returns for XML :)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.