I have 2 collections, one for appointment timeslots:
I get the proper 18 records:
dd($timeslots)
0 => {#1910 ▼
+"appt_date": Carbon\Carbon @1662465600 {#1976 ▶}
+"appt_time": Carbon\Carbon @1662465600 {#1976 ▼
#endOfTime: false
#startOfTime: false
#constructedObjectId: null
#localMonthsOverflow: null
#localYearsOverflow: null
#localStrictModeEnabled: null
#localHumanDiffOptions: null
#localToStringFormat: null
#localSerializer: null
#localMacros: null
#localGenericMacros: null
#localFormatFunction: null
#localTranslator: null
#dumpProperties: array:3 [▶]
#dumpLocale: null
#dumpDateProperties: null
date: 2022-09-06 08:00:00.0 America/New_York (-04:00)
}
+"appt_type_id": 2
}
... all the other records
17 => {#1741 ▶}
]
#escapeWhenCastingToString: false
}
I also have a collection of booked appointments, and there are 10 in it:
dd($booked)
lluminate\Support\Collection {#2190 ▼
#items: array:10 [▼
0 => App\Models\Appt {#2047 ▶}
... all the other records
9 => App\Models\Appt {#2151 ▼
#connection: "mysql"
#table: "appt"
+primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
+preventsLazyLoading: false
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#escapeWhenCastingToString: false
#attributes: array:7 [▼
"id" => 19415
"appt_type_id" => 2
"appt_status_id" => 2
"appt_date" => "2022-09-06"
"appt_time" => Carbon\Carbon
"patient_id" => 44
"appt_note" => "some note"
]
#escapeWhenCastingToString: false
}
I need to merge the data, but only keep the timeslots that are NOT in the appts collection and I need it in order by the carbon date. I've tried naming the timeslot field appt_time and so many things but I just cannot get it!
I've tried $timeslots->merge($booked). I've tried $timeslots->concat($booked), I've tried filering the $times collection using $filtered = $times->pluck('timeslot')->whereNotIn('timeslot', $booked->pluck('appt_time'));
It should look something like this:
0 => {
appt_date: '2022-09-06,
appt_time: "08:00:00" (Carbon or String, whatever works),
appt_type_id: 2
}
1 -> { "id" => 19415
"appt_type_id" => 2
"appt_status_id" => 2
"appt_date" => "2022-09-06"
"appt_time" => Carbon\Carbon (that shows 08:10:00 for that date)
"patient_id" => 44
"appt_note" => "some note"
}
2 => {
appt_date: '2022-09-06,
appt_time: "08:20:00" (Carbon or String, whatever works),
appt_type_id: 2
}
.. all the rest of the records.
Can somene please help me? In my view, I display basic info about the booked appt OR a button to schedule that time, and it's the final piece I just can't get right.