Skip to content

Abstract Data inside Data property? #706

Answered by RomainMazB
RomainMazB asked this question in Q&A
Discussion options

You must be logged in to vote

Ok, I successfully adapted the EloquentCast class to an other one implementing the Cast and Transformer:

class DataEloquentCast implements Cast, Transformer
{
    protected DataConfig $dataConfig;

    public function __construct(
        /** @var class-string<\Spatie\LaravelData\Contracts\BaseData> $dataClass */
        protected string $dataClass,
        /** @var string[] $arguments */
        protected array $arguments = []
    ) {
        $this->dataConfig = app(DataConfig::class);
    }

    protected function isAbstractClassCast(): bool
    {
        return $this->dataConfig->getDataClass($this->dataClass)->isAbstract;
    }

    public function cast(DataProperty $property, mixed $v…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@SimonMacIntyre
Comment options

Answer selected by RomainMazB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants