Overview
Thereservations:check command is an automated task that processes expired reservations and updates the status of associated tables. This command runs hourly to ensure that tables are automatically marked as available once their reservation time has passed.
Command Signature
What It Does
The command performs the following operations:Find Expired Reservations
Queries all reservations where both the date and time are less than or equal to the current date/time.
Update Table Status
For each expired reservation, updates the associated table’s status to
disponible (available).Implementation
Full Command Class
How It Works
- Current Time Reference: Uses
Carbon::now()to get the current date and time - Query Expired Reservations: Finds reservations where:
dateis less than or equal to today’s datetimeis less than or equal to the current time
- Process Each Reservation:
- Retrieves the associated
Tablemodel via the relationship - Updates the table status to
disponible - Deletes the reservation record
- Retrieves the associated
- Output: Displays success message
Manual Execution
You can run this command manually at any time:Scheduled Execution
Cron Schedule Configuration
The command is configured to run automatically every hour inapp/Console/Kernel.php:
Setting Up Laravel Scheduler
To enable automatic execution, you need to add a single cron entry to your server:reservations:check command hourly according to the schedule defined in the Kernel.
Make sure to replace
/path-to-your-project with the actual absolute path to your Laravel application.Output and Logging
Console Output
When executed, the command outputs:- Success message:
"Reservaciones vencidas procesadas correctamente."
Logging Recommendations
While the command doesn’t include built-in logging, you can monitor its execution: View Scheduled Tasks:Related Models
- Reservation Model: See Reservation API for reservation structure
- Table Model: See Tables API for table management
Use Cases
- Automatic Table Turnover: Ensures tables become available automatically after reservation times pass
- Database Maintenance: Keeps the reservations table clean by removing old records
- Real-time Availability: Maintains accurate table availability status for new reservations
- Staff Efficiency: Reduces manual intervention needed to update table statuses
Troubleshooting
Command Not Running Automatically
No Reservations Being Processed
- Verify there are expired reservations in the database
- Check the system time is correct
- Ensure the
Reservationmodel has the correct table name and relationships