Does not display relationship data within WITH

Asked

Viewed 46 times

1

I have a relationship Polymorphic between Customer and Car Class.

Client class:

public function carros()
{
    return $this->morphMany(Carro::class, 'dono');
}

Car Class:

public function dono()
{
    return $this->morphTo();
}

I am doing a search and in the result the Owner’s data appears as NULL.

$result=Carro::with('dono')->where('id',10)->get();

Now if I do the research using the Thinker values appear normally.
Where I’m going wrong to come the NULL as response in the OWNER. The values of the car come back right.

  • Try, ...where('id', 10)...

  • Sorry was the correction that added the = Aino Where. But this as you quoted. I will change. Thanks.

  • Your problem has been solved?

  • @Virgilionovic I read this question you quoted and I think mine has nothing to do with her.

  • Face for me is duplicate, because if it is not carrying something behind you did wrong, see your answer even is a problem, if there is a relationship because of Where later ???

  • @Virgilionovic looks the Where is for me to select a car and after selected I want to know its owner. I don’t see any error in Where.

  • Your question is confusing ... If you’re talking.list now puts Where in the relationship. All this is not what the question says. But all right solved your problem .

Show 2 more comments

1 answer

1


I decided to add in select the link fields with the relationship.

$result=Carro::with('dono')->select('dono_id','dono_type')->where('id',10)->get();

I don’t know why this but it makes everything work right.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.