src/Eloquent/HasMany.php
protected function findRelated($record, array $relationship)
    {
        $inverse = $this->getRelation($record, $this->key)->getRelated();
        $related = $this->findToMany($relationship);

        $related = collect($related)->filter(function ($model) use ($inverse) {
            return $model instanceof $inverse;
        });

        return new Collection($related);
    }
protected function findRelated($record, array $relationship)
    {
        $inverse = $this->getRelation($record, $this->key)->getRelated();
        $related = $this->findToMany($relationship);

        $related = collect($related)->filter(function ($model) use ($inverse) {
            return $model instanceof $inverse;
        });

        return new Collection($related);
    }
Find the related models for a JSON API relationship object.

We look up the models via the store. These then have to be filtered to
ensure they are of the correct model type, because this has-many relation
might be used in a polymorphic has-many JSON API relation.

@todo this is currently inefficient for polymorphic relationships. We
need to be able to filter the resource identifiers by the expected resource
type before looking them up via the store.

@param $record
@param array $relationship
@return Collection