Overview
The reservation system allows customers to book tables in advance. Admins and meseros (waiters) can manage reservations, assign tables, and ensure capacity requirements are met.Reservation Model
The Reservation model stores customer booking information and links to assigned tables.app/Models/Reservation.php
Reservation Attributes
Customer name for the reservation
Customer email address for confirmation
Contact phone number
Number of guests (used for table capacity matching)
Reservation date
Reservation time slot
Optional special requests or notes from customer
Foreign key to assigned table (null until assigned)
Reservation Controller
The ReservationController handles listing reservations and assigning tables.List All Reservations
app/Http/Controllers/Admin/ReservationController.php
The index method loads available tables (
status = 'disponible') for the assignment interface and eager loads existing table relationships to prevent N+1 queries.Assign Table to Reservation
The system validates that the table capacity matches the number of guests before assignment:app/Http/Controllers/Admin/ReservationController.php
Transaction Safety
Transaction Safety
The assignment process uses database transactions (
DB::transaction()) to ensure both the reservation update and table status change succeed together. If either operation fails, both are rolled back to maintain data consistency.Table-Reservation Relationship
Tables have a one-to-one relationship with reservations:app/Models/Table.php
Important: A table can only have one active reservation at a time. The status is updated to ‘reservada’ when assigned.
Capacity Validation Logic
The system enforces exact capacity matching:- Valid Assignment
- Invalid Assignment
Table Status Flow
When a table is assigned to a reservation, its status changes:Routes and Access Control
Reservation management routes are restricted to admin and mesero roles:routes/web.php
- ✅ Admin: Full access
- ✅ Mesero: Full access
- ❌ Chef: No access
- ❌ Customers: Can create through public form (not shown in source)
API Response Format
The assign table endpoint returns JSON for AJAX integration:Success Response
Success Response
Failure Response
Failure Response
Workflow Example
-
Customer Creates Reservation
- Submits name, email, phone, guest count, date, time
- Reservation created with
table_id = null
-
Mesero Reviews Reservations
- Views list at
/admin/reservations - Sees available tables filtered by status
- Views list at
-
Assign Table
- Selects table with matching capacity
- System validates:
guest count == table seats - Both records updated in transaction
-
Table Status Updates
- Table status changes to ‘reservada’
- Table appears in reserved tables list
-
Guest Arrival
- Mesero marks table as ‘ocupada’
- Reservation remains linked
-
Completion
- After service, table marked as ‘disponible’
- Reservation can be deleted or archived
Best Practices
- Exact Capacity Matching: Always enforce guest count equals table seats
- Transaction Usage: Wrap multi-model updates in database transactions
- Status Validation: Only show available tables for assignment
- Eager Loading: Use
with('table')to prevent N+1 queries - Date Ordering: Display reservations ordered by date (newest first)
- Pagination: Paginate reservation lists for performance
Common Queries
Consider implementing time-based reservation expiration to automatically release tables if guests don’t arrive within a grace period.