From f8b5e01173ed14ad732aa45809639b6fbe927d78 Mon Sep 17 00:00:00 2001 From: Damilare Anjorin Date: Fri, 5 Aug 2022 15:07:53 +0100 Subject: [PATCH 1/3] [9.x]: Add mergeUnless to resource ConditionallyLoadsAttributesTrait --- src/Illuminate/Bus/Queueable.php | 2 +- .../Http/Resources/ConditionallyLoadsAttributes.php | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Bus/Queueable.php b/src/Illuminate/Bus/Queueable.php index 3d3bbb9b290e..f485730a157c 100644 --- a/src/Illuminate/Bus/Queueable.php +++ b/src/Illuminate/Bus/Queueable.php @@ -262,7 +262,7 @@ public function dispatchNextJobInChain() } /** - * Invoke all of the chain's failed job callbacks. + * Invoke all the chain's failed job callbacks. * * @param \Throwable $e * @return void diff --git a/src/Illuminate/Http/Resources/ConditionallyLoadsAttributes.php b/src/Illuminate/Http/Resources/ConditionallyLoadsAttributes.php index d9e636de583c..79c1e16ac0bc 100644 --- a/src/Illuminate/Http/Resources/ConditionallyLoadsAttributes.php +++ b/src/Illuminate/Http/Resources/ConditionallyLoadsAttributes.php @@ -132,6 +132,18 @@ protected function mergeWhen($condition, $value) return $condition ? new MergeValue(value($value)) : new MissingValue; } + /** + * Merge a value based on a falsy condition. + * + * @param bool $condition + * @param mixed $value + * @return \Illuminate\Http\Resources\MergeValue|mixed + */ + protected function mergeUnless($condition, $value) + { + return ! $condition ? new MergeValue(value($value)) : new MissingValue; + } + /** * Merge the given attributes. * From a7b4e2ae04b32c0defa0666cac8c65e26769d579 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 5 Aug 2022 09:11:05 -0500 Subject: [PATCH 2/3] Update Queueable.php --- src/Illuminate/Bus/Queueable.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Bus/Queueable.php b/src/Illuminate/Bus/Queueable.php index f485730a157c..3d3bbb9b290e 100644 --- a/src/Illuminate/Bus/Queueable.php +++ b/src/Illuminate/Bus/Queueable.php @@ -262,7 +262,7 @@ public function dispatchNextJobInChain() } /** - * Invoke all the chain's failed job callbacks. + * Invoke all of the chain's failed job callbacks. * * @param \Throwable $e * @return void From 1b64f13735f955c242997a23d77e4f5434e14201 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 5 Aug 2022 09:11:37 -0500 Subject: [PATCH 3/3] Update ConditionallyLoadsAttributes.php --- .../Http/Resources/ConditionallyLoadsAttributes.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Http/Resources/ConditionallyLoadsAttributes.php b/src/Illuminate/Http/Resources/ConditionallyLoadsAttributes.php index 79c1e16ac0bc..177188e67a8a 100644 --- a/src/Illuminate/Http/Resources/ConditionallyLoadsAttributes.php +++ b/src/Illuminate/Http/Resources/ConditionallyLoadsAttributes.php @@ -121,7 +121,7 @@ protected function merge($value) } /** - * Merge a value based on a given condition. + * Merge a value if the given condition is truthy. * * @param bool $condition * @param mixed $value @@ -133,7 +133,7 @@ protected function mergeWhen($condition, $value) } /** - * Merge a value based on a falsy condition. + * Merge a value unless the given condition is truthy. * * @param bool $condition * @param mixed $value