I'm currently struggling with setting up a table made up of editable rows that represent records in my database. Each row has a number of input fields that I want to wire:model
so they enter a value, and then the database is updated and the change is reflected on the page.
I'm using something like <input wire:model="taskArray.{{ $task->id }}.variableName"/>
for each row, which seems to work, kind of.
The component will receive the array and the data is there if I dd()
the $taskArray
. However, once the initial change is made to the variable value, it's not showing on the front end, because it's reading the $taskArray
, which is empty until something changes.
So I've tried just setting the value
attribute of the input, but that doesn't work because wire:model
(in my experience) doesn't allow you to set a value, it wants to set it based on the variable value, which is an empty array I'm using to just push the data to the database. If I could set a value based on the actual eloquent model, that would solve my problem, but it doesn't seem possible.
So my next thought was to build an array when the page loads of all the values, but then I have to continually rebuild that array everytime a value changes and it just feels extremely hacky. There's gotta be a better way that I'm missing.
Should I be looking to use alpine and @entangle
, or what? This is the biggest thing I've struggled with in Livewire is just getting things to work when there's multiple inputs dynamically generated.
I've also tried converting each row to a nested livewire component and that turned out to be a total cluster. I'm really stuck on this and it feels like it should just work with the value
attribute or something.
What am I doing wrong?
I should mention I'm using the bootstrap datepicker library for the input, as it's a date picker. Perhaps that could be playing into it, but I'm not sure.
Happy to share more code, just not sure where to start and there's a good bit of code I could share.