lumen-framework: Results are duplicated by column numbers

Hi there!

I am build a simple query using Eloquent. I have the following action in my controller:

  public function index()
  {
    $beds = Bed::all();
    return response()->json($beds);
  }

This is the json result:

[
  {
    "0": 2,
    "1": 2000001,
    "2": 3,
    "3": "2016-02-02 21:43:58",
    "4": "2016-02-02 21:43:58",
    "id": 2,
    "bed_id": 2000001,
    "status_id": 3,
    "created_at": "2016-02-02 21:43:58",
    "updated_at": "2016-02-02 21:43:58"
  },
  {
    "0": 3,
    "1": 2000002,
    "2": 4,
    "3": "2016-02-02 21:43:58",
    "4": "2016-02-02 21:43:58",
    "id": 3,
    "bed_id": 2000002,
    "status_id": 4,
    "created_at": "2016-02-02 21:43:58",
    "updated_at": "2016-02-02 21:43:58"
  }
]

The problem is not directly in this query, but any response has duplicates columns (as numbers).

Any thoughts?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 18 (6 by maintainers)

Most upvoted comments

Finally the problem was solved.

When the database.php file is created, you need to add the fetch param, like this:

<?php

return [

    'fetch' => PDO::FETCH_CLASS,
...
]