Skip to content

Commit 13d637c

Browse files
committed
New relationship type: morph many
Require PHP 7.0+
1 parent 68f0940 commit 13d637c

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
],
1010
"license": "MIT",
1111
"require": {
12-
"php": ">=5.5.9",
12+
"php": ">=7.0.0",
1313
"nesbot/carbon": "^1.20",
1414
"doctrine/inflector": "~1.0"
1515
},

src/Model.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,22 @@ public function key($primaryKey = null)
356356
return $key;
357357
}
358358

359+
/**
360+
* Fetch a "morph many" relationship.
361+
*
362+
* @param string $relatedType
363+
* @param string $baseObject
364+
* @param string $baseObjectKey
365+
* @param string|null $primaryKey
366+
* @return Builder
367+
*/
368+
public function morphMany($relatedType, $baseObject = 'baseObject', $baseObjectKey = 'baseObjectKey', $primaryKey = null)
369+
{
370+
return $this->client->model($relatedType)
371+
->filter('@' . $baseObject, $this->type)
372+
->filter('@' . $baseObjectKey, $this->key($primaryKey));
373+
}
374+
359375
/**
360376
* Create a new model instance.
361377
*

0 commit comments

Comments
 (0)