Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

LaBoite's avatar

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

0 likes
4 replies
Mareco's avatar
Mareco
Best Answer
Level 4

@LaBoite

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.

1 like
LaBoite's avatar

@Mareco THAAAAAANK YOUU πŸ™πŸ™πŸ™ thank also for advice about $checkUnavailableSlots (I use it) πŸ™

Please or to participate in this conversation.