Skip to content
Advertisement

Attempt to read property id on bool in Laravel

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

JavaScript

I get this error

Attempt to read property “room_id” on bool

meanwhile $hotel variable is not a boolean

Advertisement

Answer

Your code can be processed by the compiler as

JavaScript

in that case you can see $hotel is a bool result from the && operator.

You should add parenthesis to counter the issue

JavaScript

or in a more clear way

JavaScript

Or using relation and using way less performance (using only a count query)

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement