Support the ongoing development of Laravel.io →
posted 10 years ago
Database
Last updated 2 years ago.
0

You use get(['id']) so Eloquent can't match loaded user(s) with relation parent - url. You need to select foreign key too:

get(['id','user_id']);
Last updated 2 years ago.
0

yes, that was a problem, here response:

{
    "error": false,
    "urls": [
        {
            "id": "3",
            "user_id": "17",
            "user": {
                "id": "17",
                "username": "firstuser"
            }
        },
        {
            "id": "4",
            "user_id": "17",
            "user": {
                "id": "17",
                "username": "firstuser"
            }
        }
    ]
}

@jarektkaczyk now i need implement some custom function to hide user_id ? right?

Last updated 2 years ago.
0

You can use $hidden property on the model.

But I encourage you to use transformers when you output json, if that's the case.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.