How to evaluate whenLoaded only when the relationship is preset? #100
-
I have the following property in a data class: public Lazy|ModelVersionData|null $modelVersion, It's a When I use the following Lazy loader I received an error: Lazy::whenLoaded('modelVersion', $model, fn () => ModelVersionData::from($model->modelVersion)),
// Error:
// Could not create a `App\Data\ModelVersionData` object from value with type `NULL` So I have to write it as this: Lazy::whenLoaded('modelVersion', $model, fn () => $model->modelVersion ? ModelVersionData::from($model->modelVersion) : null), Is there a way to make this work more like Laravel's Resources, where it simply returns |
Beta Was this translation helpful? Give feedback.
Answered by
rubenvanassche
Feb 16, 2022
Replies: 1 comment
-
Hi @benjivm, This should be fixed in the release later today! |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
benjivm
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @benjivm,
This should be fixed in the release later today!