N
N
Nikita Dergachov2017-09-06 11:42:45
Laravel
Nikita Dergachov, 2017-09-06 11:42:45

How to remove extra keys from nested eager loading?

Good afternoon.
I have a query:

$company = $this->where('id', $id)->with('streets.houses')->first();

The request returns me:
"id": 1,
        "name": "fdg",
        "phone": "gfdgfd",
        "phone_director": "gdfgfd",
        "address": "gfdgd",
        "coordinates": "gfdg",
        "created_at": "2017-09-06 11:15:23",
        "updated_at": "2017-09-06 11:15:24",
        "id_user": 44,
        "streets": [
            {
                "id": 1,
                "name": "sdfsdf",
                "created_at": "2017-09-06 11:15:34",
                "updated_at": "2017-09-06 11:15:34",
                "id_management_company": 1,
                "houses": [
                    {
                        "id": 1,
                        "name": "sdfdsf",
                        "created_at": "2017-09-06 11:15:53",
                        "updated_at": "2017-09-06 11:15:54",
                        "id_street": 1
                    },
                    {
                        "id": 2,
                        "name": "ghjhg",
                        "created_at": "2017-09-06 11:16:02",
                        "updated_at": "2017-09-06 11:16:02",
                        "id_street": 1
                    }
                ]
            },

How can I remove the keys id_streets and id_management_company.
Connections:
public function streets(){
        return $this->hasMany(Street::class, 'id_management_company');
    }

public function houses()
    {
        return $this->hasMany(House::class, 'id_street');
    }

If I add select without a key in the connection, then the query does not work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mokhirjon Naimov, 2017-09-06
@vanillathunder

Hiding Attributes From JSON

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question