Fill the gaps in a café staff rota, in Filament
A café by the harbour has four full-time staff and six part-timers. Lunch is busy when there are many table bookings, and the evenings are quiet, except when they are not. The manager plans the month in a spreadsheet: a code per person per day, OP for opening, MD for middle, CL for closing. What the spreadsheet does not say is whether there are enough people at two o'clock on Monday, or that the part-timer who just got an extra shift is now working ten days in a row.
This article shows the same month with Warp Shift: the roster counts the people working in each part of the day against what is needed, a day opens as bars on a timeline, and every change is checked against the café's rules as it is made. All pictures are from the live demo.
The scene: a month, with the gaps in red
The roster looks like the spreadsheet: staff down the side, days across, a code in each cell. Under the staff, rows count the people working in each part of the day against how many are needed. A red cell is a gap: on Monday the 2nd, 11 to 14 has 2 people where 5 are needed.
Step 1: describe the roster
The roster is a page class. Its static roster() says who is on it, which codes can be typed and where the numbers come from. This is the demo's, a little shortened:
use Qalainau\FilamentWarpShift\Pages\ShiftRoster;
use Qalainau\FilamentWarpShift\Roster;
class CafeRoster extends ShiftRoster
{
public static function roster(Roster $roster): Roster
{
return $roster
->staff(User::class)
->staffQuery(fn (Builder $query, string $shop) => $query->where('ward', $shop)->orderBy('team'))
->scopes(fn () => ['harbor' => 'Harbor café', 'station' => 'Station café'])
->codes(['OP', 'MD', 'CL', 'O'])
// Typing 10-15 in an empty cell makes a Middle shift at those times
->timeCode('MD')
// 45 minutes of break over 6 hours, an hour over 8 hours
->breaks(fn (int $minutes) => $minutes > 480 ? 60 : ($minutes > 360 ? 45 : 0))
// Staff needed at lunch from the day's table bookings, not typed on the roster
->requirements(fn (CarbonImmutable $date, string $shop) => CafeBookings::staffNeeded($date, $shop))
->rules([
MaxConsecutiveDays::make(5),
MinRestHours::make(10)->warn(),
MaxHours::make(fn (User $user) => $user->contract_hours)->warn(),
]);
}
}
requirements() is the interesting line: the number of people needed comes from your own data (here, the table bookings of the day), so the roster turns red when bookings come in, not when someone remembers to update it.
Step 2: open the day
Click a day, and it opens as a timeline: a bar per shift, and on top, people working against people needed, hour by hour. On Monday the 2nd, the red is clear: 13:00 to 16:00 and 17:00 to 20:00.
Step 3: drag a shift longer
Tom closes at 22:00. The manager drags the left end of his bar from 16:00 to 13:00, and the afternoon gap is gone.
Dragging the middle of a bar moves it; dragging across an empty row adds a shift.
Step 4: type the times
Kenji, a part-timer, has the day off. The manager types 17-20 into his cell. The list offers Use these times, and Enter makes a Middle shift from 17:00 to 20:00, because timeCode('MD') says so. The break is worked out from the length.
Step 5: the rules answer at once
Covering Monday had a price. Kenji's week now has red corners: hover over one, and it says why. With Monday filled, he works 10 days in a row, and the café's rule is 5.
This is the point of the roster: the manager sees the cost of a change at the moment of making it, and can give the evening to someone else instead. A rule is an error by default: red, and auto-fill never breaks it. With ->warn() it is a warning: amber, and auto-fill avoids it when it can. Rest between shifts and contract hours are checked the same way.
Other scenes
- Auto-fill a month from the shift codes, the needed numbers and each person's availability.
- Publish the roster: staff see their shifts in My shifts and in their phone's calendar.
- Open shifts: post the gaps, and the first part-timer who taps "I can work it" gets the shift.
- Labour cost and budget: the cost row under the roster, against the month's budget.
- Hospitals and care homes: night shifts, "after night" days and fair weekends work the same way.
Limits worth knowing
- Up to two shifts per person per day (
twoShiftsPerDay()); three or more are not supported. - Numbers that come from
requirements()cannot be changed on the roster: change your data instead. - Auto-fill uses the shift codes' own times; it does not invent shorter times. Type or drag those.
- The budget, labour cost and whole-team rules count one roster (one shop) at a time.
Try it
Open the café roster demo, click a day with red in the bottom rows, and drag a bar or type 17-20 into a day off. No sign-up, and the data is reset every hour.