Skip to content

Commit

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

* Update ConditionallyLoadsAttributes.php

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
dammy001 and taylorotwell committed Aug 8, 2022
1 parent 45ccf22 commit e0d8284
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 e0d8284

Please sign in to comment.