From 9d46c65249944a8b6479ddbe91e2df8e6efd827f Mon Sep 17 00:00:00 2001 From: Jarvis-Zongao-Bian <61961213+Jarvis-Zongao-Bian@users.noreply.github.com> Date: Wed, 19 Jun 2024 15:37:20 -0400 Subject: [PATCH 1/3] Update ModelMerge.php To handle null value in model's attributes --- src/ModelMerge.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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); + } } } From 10cc383b7dfdd140fb3094527a113f73c367b7dd Mon Sep 17 00:00:00 2001 From: Jarvis-Zongao-Bian <61961213+Jarvis-Zongao-Bian@users.noreply.github.com> Date: Wed, 19 Jun 2024 16:32:49 -0400 Subject: [PATCH 2/3] Update ModelMerge.php To handle null value from model's attribute --- src/ModelMerge.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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); + } } } From 9c4aaeea20b2a68c6de64a41a0aa4b312a876428 Mon Sep 17 00:00:00 2001 From: Jarvis-Zongao-Bian <61961213+Jarvis-Zongao-Bian@users.noreply.github.com> Date: Wed, 19 Jun 2024 16:33:54 -0400 Subject: [PATCH 3/3] Update composer.json --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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": {