MorphMany.php 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace Illuminate\Database\Eloquent\Relations;
  3. use Illuminate\Database\Eloquent\Collection;
  4. class MorphMany extends MorphOneOrMany
  5. {
  6. /**
  7. * Get the results of the relationship.
  8. *
  9. * @return mixed
  10. */
  11. public function getResults()
  12. {
  13. return $this->query->get();
  14. }
  15. /**
  16. * Initialize the relation on a set of models.
  17. *
  18. * @param array $models
  19. * @param string $relation
  20. * @return array
  21. */
  22. public function initRelation(array $models, $relation)
  23. {
  24. foreach ($models as $model) {
  25. $model->setRelation($relation, $this->related->newCollection());
  26. }
  27. return $models;
  28. }
  29. /**
  30. * Match the eagerly loaded results to their parents.
  31. *
  32. * @param array $models
  33. * @param \Illuminate\Database\Eloquent\Collection $results
  34. * @param string $relation
  35. * @return array
  36. */
  37. public function match(array $models, Collection $results, $relation)
  38. {
  39. return $this->matchMany($models, $results, $relation);
  40. }
  41. }