I need to return this JSON with Laravel eloquent

-3

My Json:

{
   "data":[
      {
         "data":{
            "name":"Documents",
            "size":"75kb",
            "type":"Folder"
         },
         "children":[
            {
               "data":{
                  "name":"Work",
                  "size":"55kb",
                  "type":"Folder"
               },
               "children":[
                  {
                     "data":{
                        "name":"Expenses.doc",
                        "size":"30kb",
                        "type":"Document"
                     }
                  },
                  {
                     "data":{
                        "name":"Resume.doc",
                        "size":"25kb",
                        "type":"Resume"
                     }
                  }
               ]
            },
            {
               "data":{
                  "name":"Home",
                  "size":"20kb",
                  "type":"Folder"
               },
               "children":[
                  {
                     "data":{
                        "name":"Invoices",
                        "size":"20kb",
                        "type":"Text"
                     }
                  }
               ]
            }
         ]
      },
      {
         "data":{
            "name":"Pictures",
            "size":"150kb",
            "type":"Folder"
         },
         "children":[
            {
               "data":{
                  "name":"barcelona.jpg",
                  "size":"90kb",
                  "type":"Picture"
               }
            },
            {
               "data":{
                  "name":"primeui.png",
                  "size":"30kb",
                  "type":"Picture"
               }
            },
            {
               "data":{
                  "name":"optimus.jpg",
                  "size":"30kb",
                  "type":"Picture"
               }
            }
         ]
      }
   ]
}
    
asked by anonymous 23.03.2018 / 14:11

1 answer

0

Hi,

At your control you can return using the response.

Example:

$dados = new MinhaModel();
return response()->json($dados->get())

I'm implying that you already have models, you're using Eloquent and everything is correctly referenced in your controller.

I hope I have helped.

    
23.03.2018 / 18:46