See if these help https://laracasts.com/discuss?q=booking+app
Generate a room booking recurrence and then find empty rooms for each booking
I'm creating a booking system in Laravel 5.6 whereby I have a form which takes the booking details and the recurrence requirement, usually weekly bookings for 2 years+ (100+ recurrences), and then I want it to return each date with a list of rooms available. So far in the application I can generate the recurrences and can find empty rooms for a single booking, but I want an efficient way of querying multiple bookings for available rooms without having to do a single query for each recurrence. Is this possible?
The room availability query:
$AvailableRooms = Derpartment::where('id', $DepartmentID)->with(['Rooms' => function($Rooms) use ($StartTime, $EndTime)
{
$Rooms->whereDoesntHave('Clinics', function ($Clinics) use ($StartTime, $EndTime) {
$Clinics->where(function($q) use ($StartTime, $EndTime)
{
$q->where( function($r) use ($StartTime, $EndTime)
{
// Req Start before or equal to booked start & Req End is before booked End time
$r->where('StartTime', '>=', $StartTime);
$r->where('StartTime', '<', $EndTime);
});
$q->where( function($r)
{
$r->where('ClinicStatus', '=', 1);
$r->orWhere('ClinicStatus', '=', 2);
$r->orWhere('ClinicStatus', '=', 4);
});
});
$Clinics->orWhere(function($q) use ($StartTime, $EndTime)
{
$q->where( function($r) use ($StartTime, $EndTime)
{
// Req Start is before booked end & Req End is after booked end
$r->where('EndTime', '>', $StartTime);
$r->where('EndTime', '<=', $EndTime);
});
$q->where( function($r)
{
$r->where('ClinicStatus', '=', 1);
$r->orWhere('ClinicStatus', '=', 2);
$r->orWhere('ClinicStatus', '=', 4);
});
});
$Clinics->orWhere(function($q) use ($StartTime, $EndTime)
{
$q->where( function($r) use ($StartTime, $EndTime)
{
// Req Start equal or greater than Booked Start & Req End is
$r->where('StartTime', '<=', $StartTime);
$r->where('EndTime', ">=", $EndTime);
});
$q->where( function($r)
{
$r->where('ClinicStatus', '=', 1);
$r->orWhere('ClinicStatus', '=', 2);
$r->orWhere('ClinicStatus', '=', 4);
});
});
});
}])->get();
ClinicStatus is how I determine whether the clinic should be included or not (e.g. other booking in database is cancelled)
The recurrence generator is done using SimShaun's Recurr from which I get an array of dates.
Please or to participate in this conversation.