Skip to content

Differentiate explicit null from default using __UNSET__ in whenLoaded method #55381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/Illuminate/Http/Resources/ConditionallyLoadsAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ protected function whenAppended($attribute, $value = null, $default = null)
* @param mixed $default
* @return \Illuminate\Http\Resources\MissingValue|mixed
*/
protected function whenLoaded($relationship, $value = null, $default = null)
protected function whenLoaded($relationship, $value = '__UNSET__', $default = null)
{
if (func_num_args() < 3) {
$default = new MissingValue;
Expand All @@ -276,7 +276,7 @@ protected function whenLoaded($relationship, $value = null, $default = null)
return;
}

if ($value === null) {
if ($value === '__UNSET__') {
$value = value(...);
}

Expand All @@ -291,7 +291,7 @@ protected function whenLoaded($relationship, $value = null, $default = null)
* @param mixed $default
* @return \Illuminate\Http\Resources\MissingValue|mixed
*/
public function whenCounted($relationship, $value = null, $default = null)
public function whenCounted($relationship, $value = '__UNSET__', $default = null)
{
if (func_num_args() < 3) {
$default = new MissingValue;
Expand All @@ -311,7 +311,7 @@ public function whenCounted($relationship, $value = null, $default = null)
return;
}

if ($value === null) {
if ($value === '__UNSET__') {
$value = value(...);
}

Expand All @@ -328,7 +328,7 @@ public function whenCounted($relationship, $value = null, $default = null)
* @param mixed $default
* @return \Illuminate\Http\Resources\MissingValue|mixed
*/
public function whenAggregated($relationship, $column, $aggregate, $value = null, $default = null)
public function whenAggregated($relationship, $column, $aggregate, $value = '__UNSET__', $default = null)
{
if (func_num_args() < 5) {
$default = new MissingValue;
Expand All @@ -348,7 +348,7 @@ public function whenAggregated($relationship, $column, $aggregate, $value = null
return;
}

if ($value === null) {
if ($value === '__UNSET__') {
$value = value(...);
}

Expand Down
Loading