Skip to content

Commit

Permalink
[9.x]: Add whenNull to ConditionallyLoadsAtrribute trait (laravel…
Browse files Browse the repository at this point in the history
…#43600)

* [9.x]: Add whenNull to ConditionallyLoadsAtrribute

* 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 e214f9e commit f75da0a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Illuminate/Http/Resources/ConditionallyLoadsAttributes.php
Expand Up @@ -157,6 +157,20 @@ protected function attributes($attributes)
);
}

/**
* Retrieve a model attribute if it is null.
*
* @param mixed $value
* @param mixed $default
* @return \Illuminate\Http\Resources\MissingValue|mixed
*/
protected function whenNull($value, $default = null)
{
$arguments = func_num_args() == 1 ? [$value] : [$value, $default];

return $this->when(is_null($value), ...$arguments);
}

/**
* Retrieve a model attribute if it is not null.
*
Expand Down

0 comments on commit f75da0a

Please sign in to comment.