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

rollcasual's avatar

Convert RAW query to Laravel Eloquent

Hi guys, i'm new to laravel and would need some help in converting the following raw query to laravel eloquent.

        SELECT 
            "id","available_rooms","hotel_id"
        FROM 
            "public"."room_types" a 
        WHERE is_enabled IS TRUE 
            AND available_rooms > (
                SELECT 
                    COUNT(room_type_id)
                FROM 
                    "public"."temp_booking_room_types" b join "public"."temp_bookings" c On b.temp_booking_id = c.id
                WHERE a.id = b.room_type_id
                    AND c.check_in BETWEEN '2020-10-11' and '2020-10-26'
            );

How can i write the above query

RoomType::select('id','available_rooms','hotel_id')->where('is_enabled', true)->get();
0 likes
1 reply

Please or to participate in this conversation.