-
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: 3 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.
"Closest" i've come is something like this: