Replies: 2 comments 3 replies
-
Hi @mgsmus if you add ? to type is answered your question? class UserData extends Data
{
public function __construct(
public int $id,
public string $name,
// public string|Optional $occupation;
public ?string $occupation; // null by default
)
{
}
} |
Beta Was this translation helpful? Give feedback.
2 replies
-
@Nir-An |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
First of all, thanks for the great package!
When I try to access an unset Optional property directly, it gives me Optional, but I want it to be null. How can I do that?
Here, the occupation field should not be in the array anyway, so there is no problem here:
but here the value is returning Spatie\LaravelData\Optional instead of null
What I want is for the occupation field to return null. How can I do this with only the features provided by the package? I've wrote a method myself to do this but I'm just wondering if it can be done with the features provided by the package:
Beta Was this translation helpful? Give feedback.
All reactions