You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How do y'all handle your PATCH requests with nullable fields?
What I mean:
In PATCH conventionally, these requests should behave differently:
Should set both title and artist to null.
{
"data": {
"title": null,
"artist": null
}
}
Should set artist to null and leave title as-is.
{
"data": {
"artist": null,
}
}
With standard Laravel FormRequests, it is pretty easy: just do $model->update($validated)
But with DTOs this wouldn't work:
classSongDataextendsData
{
publicfunction__construct(
public ?string$title,
public ?string$artist,
) {
}
publicstaticfunctionrules(): array
{
return [
'title' => ['nullable', 'string'],
'artist' => ['nullable', 'string'],
];
}
}
dd($songData->title); // is it null because it explicitly requested as null, or because it wasn't in request?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
How do y'all handle your
PATCH
requests with nullable fields?What I mean:
In
PATCH
conventionally, these requests should behave differently:title
andartist
to null.artist
to null and leavetitle
as-is.With standard Laravel FormRequests, it is pretty easy: just do
$model->update($validated)
But with DTOs this wouldn't work:
Beta Was this translation helpful? Give feedback.
All reactions