staudenmeir / eloquent-has-many-deep

Laravel Eloquent HasManyThrough relationships with unlimited levels
MIT License
2.67k stars 157 forks source link

cant access model accessor when using hasManyDeepFromRelations #81

Closed ctf0 closed 4 years ago

ctf0 commented 4 years ago

the setup is as follows

public function room() { return $this->belongsTo(Room::class); }


- room
```php
public function reservation()
    {
        return $this->hasOne(Reservation::class);
    }

    public function client()
    {
        return $this->hasManyDeepFromRelations($this->reservation(), (new Reservation())->client());
    }

all working perfectly except i cant access the accessor client->someTest and here is the error

Property [some_test] does not exist on this collection instance

if u need more info, plz ask.

staudenmeir commented 4 years ago

hasManyDeepFromRelations() returns the client in a collection. Use hasOneDeepFromRelations() to get the client directly:

public function client()
{
    return $this->hasOneDeepFromRelations($this->reservation(), (new Reservation())->client());
}
ctf0 commented 4 years ago

oh thats why, hasOneDeepFromRelations is not in the readme.

many thanx for ur help 🏆