✏️ 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;
}
✏️ 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:↪️ To Reproduce Provide us a pest test like this one which shows the problem:
BookingEngine.php
BookingEngineData.php
BookingEngineTravelerData.php
https://github.com/user-attachments/assets/5ec88b92-08a4-4fe2-abf1-9ad1e628d47f
✅ Expected behavior No exception (see second show case in the video).
🖥️ Versions
Laravel: 11.26.0 Laravel Data: 4.10.1 PHP: 8.3