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
You could get all the bed ids from the reservations with a date_out bigger than the current date and status = 1, let's say you store them in $occupiedBedIds. You then query beds for all the beds that don't have their ids in $occupiedBedIds and you've got your available beds. But this is a bit messy.
What I would do would be to create another boolean column on the beds table, call it "available" and have it default to 1, then write an event listener for the saved event on the Reservation model to update the bed based on the date_out and status values. This way, to query the available beds, you just do: Bed::whereAvailable(true)->get().
can do this with me step by step I want to understand well
I want to know what I will write in model and controller and how can I use listener ?@deGecko