flugg / laravel-responder

A Laravel Fractal package for building API responses, giving you the power of Fractal with Laravel's elegancy.
MIT License
865 stars 86 forks source link

Meta data turns null #104

Closed Krato closed 6 years ago

Krato commented 6 years ago

Hi! I'm having problems with meta info.

I'm trying to do that:

return responder()->success($pieces->paginate(12))
            ->meta([
                'formats' => $formats,
                'aspects' => $aspects,
            ])->respond();

Aspects data is working fine. But not for formats array.

Aspects array is:

[
  "water" => "Water",
  "wood" => "Wood",
  "colors" => "Colors",
]

And formats array is:

[
  "45x45" => "45x45",
  "20x60" => "20x60",
  "25x75" => "25x75",
  "45x60" => "45x60",
  "60x60" => "60x60",
  "45x90" => "45x90",
]

But the response for formats meta array is:

15:null
15:null
16:null
20:null
20:null
25:null

Why is not returning me the correct array?

Thanks!

flugg commented 6 years ago

Hi, I can't seem to replicate this issue. I'm getting the following output:

{
    "status": 200,
    "success": true,
    "data": null,
    "formats": {
        "45x45": "45x45",
        "20x60": "20x60",
        "25x75": "25x75",
        "45x60": "45x60",
        "60x60": "60x60",
        "45x90": "45x90"
    },
    "aspects": {
        "water": "Water",
        "wood": "Wood",
        "colors": "Colors"
    }
}

What does your entire response data look like? And do the meta data stay the same even if you leave the success() method empty (and returning null as data)?

Krato commented 6 years ago

Thanks @flugger for your reply. Can you try with an array like next one?

[
  "8x60" => "8x60",
  "10x60" => "10x60",
  "15x90" => "15x90",
  "16x90" => "16x90",
  "20x120" => "20x120",
  "23x180" => "23x180",
  "25x75" => "25x75",
  "25x150" => "25x150",
  "30x60" => "30x60",
  "30x30" => "30x30",
  "32x90" => "32x90",
  "33x47" => "33x47",
  "33x33" => "33x33",
  "33x100" => "33x100",
  "45x90" => "45x90",
  "45x45" => "45x45",
  "50x100" => "50x100",
  "60x60" => "60x60",
  "60x120" => "60x120",
  "90x90" => "90x90",
  "100x100" => "100x100",
  "120x120" => "120x120",
]

Is giving me null results. Thanks

flugg commented 6 years ago

I still get the expected output. What version of the package are you using?

Krato commented 6 years ago

I was on version 2. But after update to 3.0 same error. But after download the response I saw the data, so I found the problem in the chrome extension I was using to format the json response. :(

Sorry for that. Is working fine.