Property [unavailable_type] does not exist on this collection instance
hello guys, how are u? have a problem with my code, trying to understand but ... :/ if u have idea plz
i want to check if this slot date is in my table "unavailable_slots" and i have unavailable_type [0: many days like a period, 1: just 1 day]
I have a rooms with slots times, and i try to make it unavailable for specific days for exemple.
Example: Room 1 is free from 12:00 to 14:00 all days -> i want to make it from 12/12/2022 to 01/01/2023 So I create new record and will check it when i fetch the roomTimes if not exist in my unavailable_slots table
my code:
$check_unavailable_slot = UnavailableSlot::where('room_id', $room->id)->get();
if ($check_unavailable_slot->unavailable_type == 0){
dd('its ok');
}
I have this error : Property [unavailable_type] does not exist on this collection instance And not go inside my if
=> And I can add many unvailable slots for same room
Thanks for your help
So there is a problem. You are accessing "unavailable_type" on array of UnavailableSlot objects.
Your code should work well with something like this:
$check_unavailable_slots = UnavailableSlot::where('room_id', $room->id)->get();
foreach($check_unavailable_slots as $slot) {
if ($slot->unavailable_type === 0) {
dd('its ok');
}
}
Btw. Convention is writing variables with camelCase, so for example: $checkUnavailableSlots.
Hope, it helps.
Please or to participate in this conversation.