Skip to content

Commit

Permalink
[9.x]: Add mergeUnless to resource ConditionallyLoadsAttributes t…
Browse files Browse the repository at this point in the history
…rait (laravel#43567)

* [9.x]: Add mergeUnless to resource ConditionallyLoadsAttributesTrait

* Update Queueable.php

* Update ConditionallyLoadsAttributes.php

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
2 people authored and Ken committed Aug 9, 2022
1 parent c9b23d9 commit e7a9cb1
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Illuminate/Http/Resources/ConditionallyLoadsAttributes.php
Expand Up @@ -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
Expand All @@ -132,6 +132,18 @@ protected function mergeWhen($condition, $value)
return $condition ? new MergeValue(value($value)) : new MissingValue;
}

/**
* Merge a value unless the given condition is truthy.
*
* @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.
*
Expand Down

0 comments on commit e7a9cb1

Please sign in to comment.