Accessing repeater data

Hi, I implemented repeater on my form. I don't want to change my table column to json type so I was thinking of just iterate each value inside of the repeater data by using foreach and apply something on it before saving. How can I access stored repeater data?
17 Replies
Dan Harrin
Dan Harrin2y ago
are you using the admin panel?
Resonance
ResonanceOP2y ago
Yes I understand that $data['nameoffield'] can access the repeater but it is stored as an array, and I want to get those data inside of that array and do like foreach to iterate each of that repeater data to my normal fields so that I can save it as normal data. Like Field1 Repeater with 2 field Field2 And I want to do Field 1 Repeater data [0]1 Field 2 Field 1 Repeater data [1]1 Field 2
Dan Harrin
Dan Harrin2y ago
i dont understand the mutate function is probably what youre looking for though
Resonance
ResonanceOP2y ago
I just want to access the repeater array data
Dan Harrin
Dan Harrin2y ago
when?
Resonance
ResonanceOP2y ago
My form modal looks like this
Resonance
ResonanceOP2y ago
And I want to access this data
Resonance
ResonanceOP2y ago
So that I can use foreach to iterate those data And save it just like
{
"patient_name": "Test",
"pharmacy_stocks_id": "1",
"dispensed_qty": "10"
"dispensed_by": "Admin@MHO_West",
"dispensed_date": "2023/03/12 06:46:40"
}

{
"patient_name": "Test",
"pharmacy_stocks_id": "1",
"dispensed_qty": 20
"dispensed_by": "Admin@MHO_West",
"dispensed_date": "2023/03/12 06:46:40"
}
{
"patient_name": "Test",
"pharmacy_stocks_id": "1",
"dispensed_qty": "10"
"dispensed_by": "Admin@MHO_West",
"dispensed_date": "2023/03/12 06:46:40"
}

{
"patient_name": "Test",
"pharmacy_stocks_id": "1",
"dispensed_qty": 20
"dispensed_by": "Admin@MHO_West",
"dispensed_date": "2023/03/12 06:46:40"
}
When saving, Im gonna use mutateFormDataUsing() so that I can manipulate the data, before saving it to the database Yes, Im using mutateFormDataUsing()
wyChoong
wyChoong2y ago
Probably afterCreate/afterSave where you access $this->record->relationship()->update([…])
Resonance
ResonanceOP2y ago
Im sorry, but i dont get what you mean
Resonance
ResonanceOP2y ago
I know hooks and that's not what I needed. Repeater data are stored on $data['nameofrepeater] array. as seen in the screenshot as an array, so, an array inside of the array. What I want to do is access those data inside of repeater array so that I can use a foreach loop to iterate those data into my normal field before saving, as example on the above message.
Resonance
ResonanceOP2y ago
This is the data thats been POST and I want to access those repeater data so that I can do a foreachloop so that my final data can look like this Doing dd ($data['dispensed_medicines']) //name of the repeater gives me the array of repeater with
array:1 [▼
0 => array:2 [▼
"pharmacy_stocks_id" => "1"
"dispensed_qty" => "10"
]
]
array:1 [▼
0 => array:2 [▼
"pharmacy_stocks_id" => "1"
"dispensed_qty" => "10"
]
]
I want to get the pharmacy_stocks_id, is it possible on $data[] array?
Dan Harrin
Dan Harrin2y ago
$data['dispensed_medicines'][0]['pharmacy_stocks_id']
Resonance
ResonanceOP2y ago
thanks dan! that do the trick
Dan Harrin
Dan Harrin2y ago
i was confused because i thought the question was about filament specifically it might be worth revising your knowledge on PHP arrays
Resonance
ResonanceOP2y ago
Well, im using filament, and repeater recomment that to store data in a JSON column. I dont want to do that, because, normalization. Im trying that but without the 3rd part so the output was like a single string. im sorry mybad
Want results from more Discord servers?
Add your server