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

nitiphone's avatar

laravel query room available

Dear All, According to I have 2 tables and I would like to show available room on system so I have command below for example So My question is How can I create it as eloquent for query these?

SELECT r.room_id
FROM rooms r
WHERE r.room_id NOT IN (
    SELECT b.room_id FROM bookings b
    WHERE NOT (b.end_datetime   < '2012-09-14T18:00'
               OR
               b.start_datetime > '2012-09-21T09:00'))
ORDER BY r.room_id;
Schema::create('tb_rooms', function (Blueprint $table) {
            $table->id();
            $table->string('room_name');
            $table->integer('roomtype_id');
            $table->tinyInteger('max');
            $table->double('price');
            $table->tinyInteger('status')->default(1);
            $table->timestamps();
        });

 Schema::create('tb_reservation_room', function (Blueprint $table) {
            $table->id();
            $table->integer('reservation_id');
            $table->integer('room_id');
            $table->tinyInteger('adult');
            $table->tinyInteger('child');
            $table->double('room_price');
            $table->date('checkin_date');
            $table->date('checkout_date');
            $table->timestamps();
        });
0 likes
2 replies
Nakov's avatar

So you just copied code from multiple places and you expect someone to finish your job?

Do you see any difference with the query you copied from somewhere and your tables?

nitiphone's avatar

@Nakov Hi, Yes can modify it as my field name but I would like to create it like eloquent style. Can you help?

Please or to participate in this conversation.