diff --git a/composer.json b/composer.json index 9004b18..c2d731a 100644 --- a/composer.json +++ b/composer.json @@ -12,11 +12,11 @@ "homepage": "https://github.com/alariva/laravel-modelmerge", "keywords": ["Laravel", "ModelMerge"], "require": { - "illuminate/support": "~5", - "illuminate/database": "~5" + "illuminate/support": "~11", + "illuminate/database": "~11" }, "require-dev": { - "phpunit/phpunit": "~6.0", + "phpunit/phpunit": "~9.4|^10.4", "orchestra/testbench": "~3.5" }, "autoload": { diff --git a/src/ModelMerge.php b/src/ModelMerge.php index a2891ea..5d35038 100644 --- a/src/ModelMerge.php +++ b/src/ModelMerge.php @@ -274,8 +274,13 @@ public function transferRelationships() public function transferChilds($relationship) { - foreach ($this->modelB->$relationship as $child) { - $this->modelA->$relationship()->save($child); + $children = $this->modelB->$relationship; + + // Check if the relationship is not null or ensure it's iterable + if ($children) { + foreach ($children as $child) { + $this->modelA->$relationship()->save($child); + } } }