Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Add Route Disabling Feature
This PR introduces the ability to temporarily disable routes without removing them from the codebase. This feature is useful for maintenance mode, feature flags, A/B testing, gradual rollouts, and emergency response scenarios.
Usage
Basic Usage - Default Message
Custom Message
Custom Response with Callback
Conditional Disabling
Implementation Details
Files Added
src/Illuminate/Routing/Middleware/DisabledRoute.php- Middleware that handles disabled routestests/Integration/Routing/DisabledRouteTest.php- Integration tests (7 tests, 16 assertions)Files Modified
src/Illuminate/Routing/Route.php- Addeddisabled()method (13 lines)tests/Routing/RoutingRouteTest.php- Added unit tests (3 tests, 6 assertions)How It Works
The
disabled()method on the Route class:DisabledRoutemiddleware to the routeThe
DisabledRoutemiddleware:Use Cases
Real-World Examples
Feature Flags
Time-Based Availability
Business Hours
Gradual Rollout
Testing
All tests pass successfully:
-3 unit tests covering:
Middleware registration
Action array storage
Different parameter types (boolean, string, callback)
Total: 10 tests, 22 assertions
Backward Compatibility
This is a non-breaking change. It only adds new functionality without modifying any existing behavior. All existing routes continue to work exactly as before.
API Design Considerations
The
disabled()method accepts three types of values:true/false) - Simple on/off switchReturning
nullfrom a callback means "do not disable" - allowing dynamic enabling/disabling based on complex conditions.Default HTTP status is 503 Service Unavailable, which is semantically correct for temporary unavailability scenarios.