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

Smsma's avatar
Level 2

how can I use event and listener to handle the booking ?

I have rooms in hospital each of one has number of beds ( 1 or 2 or 3) I want to reserve bed to certain patient how can I handle this in my project in easy way

rooms migration :

 $table->increments('id');
            $table->string('name');
            $table->integer('floor');
            $table->text('description');
            $table->timestamps();

beds migration

Schema::create('beds', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('quality');
            $table->string('charge');
            $table->integer('room_id')->unsigned();;
            $table->foreign('room_id')->references('id')->on('rooms')
                  ->onUpdate('cascade')->onDelete('cascade');
            $table->boolean('status');
            $table->timestamps(); 
        });

reservation migration

Schema::create('reservations', function (Blueprint $table) {
            $table->increments('id');
            $table->date('date_in');
            $table->date('date_out');
            $table->boolean('status');
            $table->integer('patient_id')->unsigned();
            $table->foreign('patient_id')->references('id')->on('patients');
            $table->integer('bed_id')->unsigned();
            $table->foreign('bed_id')->references('id')->on('beds');
            $table->timestamps();
        });

how can I check available beds , get Available beds and ensure that the bed is booked or not ?? how can I use event and listener to handle the booking ?

0 likes
6 replies
martinbean's avatar

@devMoaa I’m not sure where events and listeners would come in here. Events are for telling your application something happened, and then you attach listeners to do some extra work after the fact.

As for the actual logic of reserving, you’d need to create a reservation for a patient for a bed. Your models for this look fine.

1 like
martinbean's avatar

@devMoaa You got an answer from @deGecko not long after you posted your first thread.

You can’t just keep creating threads every few hours because no one’s given you the code to copy and paste for your project.

Please or to participate in this conversation.