protected function getRelatedModelsWithImages($parents, $relation)
    {
        $models = [];

        foreach ($parents as $parent) {
            // Get the related object
            $related = $parent->$relation;

            // The related object is a model (like in a belongsTo setup), add it to
            // the array
            if (is_a($related, Model::class)) {
                $models[] = $related;
            }

            // Otherwise, if the relation returns a collection (like a hasMany), add
            // all the related models to the growing array.
            elseif (is_a($related, Collection::class)) {
                $models = array_merge($models, $related->all());
            }
        }

        return $models;
    }