Cannot get a custom cast to work #479
Unanswered
abishekrsrikaanth
asked this question in
Q&A
Replies: 1 comment
-
Always follow the docs correctly, your it('will work', function (){
class TransitSubStatusCast implements Castable
{
public function __construct(public mixed $transitSubStatus)
{
}
public function status()
{
}
public static function dataCastUsing(...$arguments): Cast
{
ray($arguments);
return new class implements Cast {
public function cast(DataProperty $property, mixed $value, array $context): mixed
{
ray($context);
return new TransitSubStatusCast($value);
}
};
}
}
class DataBlaBla extends Data{
public function __construct (
#[WithCastable(TransitSubStatusCast::class)]
public TransitSubStatusCast $transitSubStatus,
) {
}
}
dd(DataBlaBla::from(['transitSubStatus' => 'a']));
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Here is my custom cast class
and here is how I am casting the argument on the constructor
Here is the error I am getting
can you please advice if I am missing something here?
Beta Was this translation helpful? Give feedback.
All reactions