Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TransformedDataCollectableResolver: Argument #1 ($data) must be of type BaseData, array given #878

Open
alexanderkroneis opened this issue Oct 8, 2024 · 0 comments

Comments

@alexanderkroneis
Copy link

✏️ Describe the bug
I'm implementing a nested Data object. When I manipulate $adults from outside (BookingEngine, which is a Livewire component) it manipulates $travelers as well. Once I type something in another input field it shows this message:

Spatie\LaravelData\Resolvers\TransformedDataCollectableResolver::Spatie\LaravelData\Resolvers\{closure}(): Argument #1 ($data) must be of type Spatie\LaravelData\Contracts\BaseData, array given, called in /var/www/vendor/spatie/laravel-data/src/Resolvers/TransformedDataCollectableResolver.php on line 81

↪️ To Reproduce
Provide us a pest test like this one which shows the problem:

BookingEngine.php

class BookingEngine extends Component
{
    public BookingEngineData $data;

    // ...

    public function decrease(string $property): void
    {
        $this->data->{$property}--;

        if ($this->data->{$property} < 0) {
            $this->data->{$property} = 0;
        }

        $this->data->travelers->pop();
    }

    public function increase(string $property): void
    {
        $this->data->{$property}++;

        $this->data->travelers->add(new BookingEngineTravelerData);
    }

BookingEngineData.php

class BookingEngineData extends Data implements Wireable
{
    use WireableData;

    /** @var Collection<int, BookingEngineTravelerData> */
    public Collection $travelers;

    // ...
}

BookingEngineTravelerData.php

class BookingEngineTravelerData extends Data implements Wireable
{
    use WireableData;

    public string $name;

    public int $age;

    public float $amount = 0.0;
}
Export-1728390048014.mp4

✅ Expected behavior
No exception (see second show case in the video).

🖥️ Versions

Laravel: 11.26.0
Laravel Data: 4.10.1
PHP: 8.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant