From be7dccca9f9249c928108d957fe70e78d370d26e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 29 Sep 2017 13:57:02 -0500 Subject: [PATCH] add interface --- .../Http/Resources/ConditionallyLoadsAttributes.php | 5 +++-- src/Illuminate/Http/Resources/MissingValue.php | 12 ++++++++++-- .../Http/Resources/PotentiallyMissing.php | 13 +++++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 src/Illuminate/Http/Resources/PotentiallyMissing.php diff --git a/src/Illuminate/Http/Resources/ConditionallyLoadsAttributes.php b/src/Illuminate/Http/Resources/ConditionallyLoadsAttributes.php index ab962bd535cc..1662fa1947b1 100644 --- a/src/Illuminate/Http/Resources/ConditionallyLoadsAttributes.php +++ b/src/Illuminate/Http/Resources/ConditionallyLoadsAttributes.php @@ -29,9 +29,10 @@ protected function filter($data) return $this->merge($data, $index, $this->filter($value->data)); } - if ($value instanceof MissingValue || + if (($value instanceof PotentiallyMissing && $value->isMissing()) || ($value instanceof self && - $value->resource instanceof MissingValue)) { + $value->resource instanceof PotentiallyMissing && + $value->isMissing())) { unset($data[$key]); $index--; diff --git a/src/Illuminate/Http/Resources/MissingValue.php b/src/Illuminate/Http/Resources/MissingValue.php index 4bd1eff4d2a2..d0d8dfa78914 100644 --- a/src/Illuminate/Http/Resources/MissingValue.php +++ b/src/Illuminate/Http/Resources/MissingValue.php @@ -2,7 +2,15 @@ namespace Illuminate\Http\Resources; -class MissingValue +class MissingValue implements PotentiallyMissing { - // + /** + * Determine if the object should be considered "missing". + * + * @return bool + */ + public function isMissing() + { + return true; + } } diff --git a/src/Illuminate/Http/Resources/PotentiallyMissing.php b/src/Illuminate/Http/Resources/PotentiallyMissing.php new file mode 100644 index 000000000000..6ed7f3c8b86c --- /dev/null +++ b/src/Illuminate/Http/Resources/PotentiallyMissing.php @@ -0,0 +1,13 @@ +