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

Aronaman's avatar

special character in query builder

in my database i have 10 bookings row from 10 i have 8 Bookable_type="App\Room", but i get zero, i think this is b/c the special character "/" . how can i solve this problem

         DB::raw("SUM(CASE WHEN bookings.bookable_type ='App\Room' THEN 1 ELSE 0 END) AS countBookedRoomMontly"),

i also try count , but give all not what i nedd

            DB::raw("COUNT(CASE WHEN bookings.bookable_type ='App\Room' THEN 1 ELSE 0 END) AS countBookedRoomMontly"),

Any Help

0 likes
4 replies
tykus's avatar

Escape it:


DB::raw("SUM(CASE WHEN bookings.bookable_type ='App\\Room' THEN 1 ELSE 0 END) AS countBookedRoomMontly")

tykus's avatar
tykus
Best Answer
Level 104

Hmmm. I put three backslashes in my response above... I guess it was escaped

Please or to participate in this conversation.