'Attempt to read property id on bool in Laravel

i tried assigning a value to a variable in an if condition

 if ($hotel = Hotel::whereCode($this->hotelCode)->first() && $room = Room::whereRoomCode($value)->first()) {
           if ($hotel->room_id == $room->id) {
                return true;
            }
}

I get this error

Attempt to read property "room_id" on bool

meanwhile $hotel variable is not a boolean



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source