Concerns
1 month ago
BelongsTo.php
2 years ago
BelongsToMany.php
1 month ago
HasMany.php
2 years ago
HasManyThrough.php
1 month ago
HasOne.php
1 month ago
HasOneOrMany.php
1 month ago
HasOneThrough.php
2 years ago
MorphMany.php
2 years ago
MorphOne.php
1 month ago
MorphOneOrMany.php
2 years ago
MorphPivot.php
1 month ago
MorphTo.php
6 months ago
MorphToMany.php
2 years ago
Pivot.php
2 years ago
Relation.php
1 month ago
MorphMany.php
56 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWPSCOPED\Illuminate\Database\Eloquent\Relations; |
| 4 | |
| 5 | use IAWPSCOPED\Illuminate\Database\Eloquent\Collection; |
| 6 | /** @internal */ |
| 7 | class MorphMany extends MorphOneOrMany |
| 8 | { |
| 9 | /** |
| 10 | * Get the results of the relationship. |
| 11 | * |
| 12 | * @return mixed |
| 13 | */ |
| 14 | public function getResults() |
| 15 | { |
| 16 | return !\is_null($this->getParentKey()) ? $this->query->get() : $this->related->newCollection(); |
| 17 | } |
| 18 | /** |
| 19 | * Initialize the relation on a set of models. |
| 20 | * |
| 21 | * @param array $models |
| 22 | * @param string $relation |
| 23 | * @return array |
| 24 | */ |
| 25 | public function initRelation(array $models, $relation) |
| 26 | { |
| 27 | foreach ($models as $model) { |
| 28 | $model->setRelation($relation, $this->related->newCollection()); |
| 29 | } |
| 30 | return $models; |
| 31 | } |
| 32 | /** |
| 33 | * Match the eagerly loaded results to their parents. |
| 34 | * |
| 35 | * @param array $models |
| 36 | * @param \Illuminate\Database\Eloquent\Collection $results |
| 37 | * @param string $relation |
| 38 | * @return array |
| 39 | */ |
| 40 | public function match(array $models, Collection $results, $relation) |
| 41 | { |
| 42 | return $this->matchMany($models, $results, $relation); |
| 43 | } |
| 44 | /** |
| 45 | * Create a new instance of the related model. Allow mass-assignment. |
| 46 | * |
| 47 | * @param array $attributes |
| 48 | * @return \Illuminate\Database\Eloquent\Model |
| 49 | */ |
| 50 | public function forceCreate(array $attributes = []) |
| 51 | { |
| 52 | $attributes[$this->getMorphType()] = $this->morphClass; |
| 53 | return parent::forceCreate($attributes); |
| 54 | } |
| 55 | } |
| 56 |