Does not display relationship data within WITH [duplicate]

1

I have a Polymorphic Relationship between the 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 data appears as NULL .

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

Now if I do the search using Thinker the values appear normally. Where am I wrong to see NULL as answer in DONO. The car values come back straight.

    
asked by anonymous 16.04.2018 / 20:41

1 answer

1

I resolved by adding the link fields in the relationship to the select.

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

I do not know why this makes everything work right.

    
19.04.2018 / 19:18