Replies: 3 comments 1 reply
-
Hi @ragulka you can use class SongData extends Data
{
public function __construct(
public string $title,
public string $artist,
) {
}
public static function fromModel(Song $song): self
{
return new self(
tags: $song->tags ?? auth()->user->default_song_tags,
);
}
} |
Beta Was this translation helpful? Give feedback.
-
No, as you already understand you can create scenarios for all different types. the default value (and the source of the value) for a request could be different from the default value for a model or custom array and so on . Maybe change the discussion category from question to Idea? it's up to you. |
Beta Was this translation helpful? Give feedback.
-
You could always create a pipe which uses such a method and adds the values to the payload. It looks a bit overkill and opening a box of pandora of possible outcomes when we add it to the package. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Is there a way to provide default property values from the database? I have a use-case where a property must be present on the data object for it to be valid, but if not provided by the user, it should default to a predefined value on user's settings, which are stored in DB.
Ie, something like this:
Beta Was this translation helpful? Give feedback.
All reactions