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

Livewire Synths not working in data object contains an array #836

Open
Glennmen opened this issue Aug 9, 2024 · 3 comments
Open

Livewire Synths not working in data object contains an array #836

Glennmen opened this issue Aug 9, 2024 · 3 comments

Comments

@Glennmen
Copy link

Glennmen commented Aug 9, 2024

✏️ Describe the bug
When using the data object in Livewire wire:model.live="startupRule.daysActive" it produces an exception on model update. We are using it in a input checkbox.

↪️ To Reproduce

class PowerscheduleRuleData extends Data
{
    public ?array $daysActive = [];
}
2024-08-09 10:58:25] local.ERROR: Spatie\LaravelData\Support\Livewire\LivewireDataSynth::get(): Return value must be of type Spatie\LaravelData\Contracts\BaseData, array returned {"userId":"4","exception":"[object] (TypeError(code: 0): Spatie\\LaravelData\\Support\\Livewire\\LivewireDataSynth::get(): Return value must be of type Spatie\\LaravelData\\Contracts\\BaseData, array returned at /var/www/html/vendor/spatie/laravel-data/src/Support/Livewire/LivewireDataSynth.php:35)

I was able to fix it by editingthe get(&$target, $key) in LivewireDataSynth and by removing the return value BaseData typecast:

public function get(&$target, $key)
{
    return $target->{$key};
}

But not sure if that is the correct solution.

✅ Expected behavior
Laravel data to work with Livewire in two way binding.

🖥️ Versions

Laravel: 11.16.0
Laravel Data: 4.7.2
PHP: 8.2
Livewire: 3.5.4

@rubenvanassche
Copy link
Member

Can you provide me a demo repository showing this issue?

@Glennmen
Copy link
Author

Sorry for the delay, I have been very busy. I will try to setup something this week.

@Glennmen
Copy link
Author

@rubenvanassche Here you can see the issue that we where having: https://github.com/Glennmen/DemoLaravelDataBug

Very basis setup, can be run with artisan serve and then on the homepage you can see the error when changing the checkboxes.

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

2 participants