S
S
smilelan2020-10-05 19:40:07
Laravel
smilelan, 2020-10-05 19:40:07

Resource API not working with linking table?

Good evening everyone!
There is a relationship between the User and his contacts, which is carried out through one to many, in UserInfo it looks like this:

public function contacts()
    {
        return $this->hasMany(Contact::class);
    }

When I try to organize the Resource api, for some reason the data does not arrive in it, I do this
$arrayInfo = ContactResource::collection($info->contacts);

However, if you do so
$arrayInfo = ContactResource::collection(Contact::where('user_id', 20)->get()) ;

In both cases, the same collection is obtained.

Everything works, what am I doing wrong?
Thanks for helping me solve

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin B., 2020-10-05
@Kostik_1993

So maybe some kind of hat is being made in the resource itself, how can we know, you won’t show your super secret code

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question