I need to return this JSON with Laravel eloquent

Asked

Viewed 86 times

-3

Meu 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"
               }
            }
         ]
      }
   ]
}
  • If could have explained from where and how? for example the models that could generate this layout is already a good start... really question unclear!

1 answer

0

Hi,

In your control you can return using Sponse.

Example:

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

I’m implying that you already have models, are using Eloquent and are all referenced correctly in your controller.

I hope I’ve helped.

Browser other questions tagged

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