Level 13
Never mind....
Serialised it all to the database. Not ideal as i wanted to do them separate and have a relationship there.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi. Im completely baffled on how to save multiple groups of arrays to a database or even if its possible.
What im trying to do is
@foreach($customers as $customer)
<input type="checkbox" name="activity_1[]" value="1">
Pre-Book this for <strong>{{ $customer->name }}</strong>
@endforeach
@foreach($customers as $customer)
<input type="checkbox" name="activity_2[]" value="1">
Pre-Book this for <strong>{{ $customer->name }}</strong>
@endforeach
@foreach($customers as $customer)
<input type="checkbox" name="activity_3[]" value="1">
Pre-Book this for <strong>{{ $customer->name }}</strong>
@endforeach
So there could be 1-3 customers in each activity.
I want to do it so it saves to the database as a relationship
So the database is like this::
customer 1
customer 2
Any help would be greatful. I have tried this::
$activities = $request->activity_1;
$activities_2 = $request->activity_2;
$activities_3 = $request->activity_3;
foreach ($activities as $index => $activity) {
$activity = new Activity();
$activity->activity_1 = $activity;
$activity->activity_2 = $activity_2[$index];
$activity->activity_3 = $activity_3[$index];
$activity->save();
}
but i get 0 in the columns. but if i return the $activities array it shows that its ok.
Please or to participate in this conversation.