Optional vs. Nullable in Spatie Laravel Data: What's the Difference? #945
-
What's the difference between marking a property as Perhaps it would be helpful if the documentation included an example for further clarification. Many thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Marking a property as optional means that if its value is |
Beta Was this translation helpful? Give feedback.
Marking a property as optional means that if its value is
null
, it will be omitted when transforming the object. On the other hand, using a nullable type (?string
) ensures the property is always present in the transformed array/JSON, even if its value isnull
.