-
|
Given the following example
I'm assuming i'm using it incorrectly, what i'm really trying to do is automatically set a property on the object, based on the input/state of the object, achieving something akin to computed properties in vue. Can anyone give me a pointer to the best way of doing this for this package? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
|
"Closest" i've come is something like this: |
Beta Was this translation helpful? Give feedback.
-
|
Hi @ovp87 What about native '?' without class Test extends Data
{
public readonly ?bool $test1;
public readonly ?int $test2;
public function __construct(public string $name) {
$this->test1 = $name === 'hello world';
$this->test2 = $name === 'hello world' ? 1234 : 5678;
}
}
|
Beta Was this translation helpful? Give feedback.
-
|
Have you already taken a look at optional properties? https://spatie.be/docs/laravel-data/v2/as-a-data-transfer-object/optional-properties |
Beta Was this translation helpful? Give feedback.
-
|
@rubenvanassche, it says
But it doesn't say how to determine the value of Either way, that isn't the point for me. In my case, as a diligent developer, I have an type: object
minProperties: 1
propertyNames:
$ref: MyEnum
additionalProperties:
type: stringThis is great, because in order to allow anothe property (all have the same type), I only need to add a new value to I can use an associative array e.g. But now my DTO translates to having a property Right now, I have to resort to adding a separate property to the DTO, one for each enum member. |
Beta Was this translation helpful? Give feedback.
"Closest" i've come is something like this: