Download the PHP package nikolawd/laravel-route-disabling without Composer
On this page you can find all versions of the php package nikolawd/laravel-route-disabling. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nikolawd/laravel-route-disabling
More information about nikolawd/laravel-route-disabling
Files in nikolawd/laravel-route-disabling
Package laravel-route-disabling
Short Description Temporarily disable Laravel routes without removing them from the codebase. Originally proposed for Laravel core.
License MIT
Informations about the package laravel-route-disabling
Laravel Route Disabling
Temporarily disable Laravel routes without removing them from the codebase. Perfect for maintenance mode, feature flags, A/B testing, and gradual rollouts.
The implementation follows Laravel's internal patterns for route handling and has been thoroughly tested to work with route caching.
Installation
You can install the package via Composer:
The package will automatically register its service provider.
Usage
Basic Usage - Default Message
Custom Message
The package uses Laravel's native error handling system (abort(503, $message)), which means:
- Laravel automatically displays its styled 503 error page
- You can customize the page by creating
resources/views/errors/503.blade.phpin your app - The
$exception->getMessage()variable contains your custom message - Full compatibility with Laravel's exception handling
Custom Response with Callback
Conditional Disabling
Dynamic Enabling/Disabling
Return null or false from a callback to allow the route to proceed normally:
Use Cases
1. Selective Maintenance Mode
Disable specific routes without putting the entire application in maintenance mode:
2. Feature Flags
Easily toggle features on/off based on configuration or environment:
3. Time-Based Availability
Enable routes only during specific time periods:
4. Business Hours
Restrict access to certain routes during business hours:
5. Gradual Rollouts
Enable features for a percentage of users:
6. Emergency Response
Quickly disable problematic endpoints in production:
Route Caching Support
This package fully supports Laravel's route caching (php artisan route:cache). Closures are automatically serialized and deserialized using Laravel's SerializableClosure, following the same pattern as Laravel's core routing system.
Testing
Customizing the 503 Error Page
Since the package uses Laravel's native error handling, you can customize the 503 error page just like any other Laravel error page:
- Create
resources/views/errors/503.blade.phpin your application - Use
$exception->getMessage()to display your custom message
Example custom error page:
Laravel will automatically use your custom view instead of the default error page.
How It Works
The package uses Laravel's macro system to add disabled() and getDisabled() methods to the Route class with full type hinting support. When a route is disabled:
- The disabled status/message/callback is stored in the route action array
- A middleware is automatically registered to the route
- The middleware checks if the route is disabled
- For simple messages, it calls
abort(503, $message)which triggers Laravel's error handling - If a callback is provided, it's executed and the response is returned
- If the callback returns
nullorfalse, the request proceeds normally
For route caching:
- Closures are serialized using
SerializableClosure::unsigned() - Deserialization happens automatically when accessing
getDisabled() - String and boolean values are not affected by serialization
Type Hints
All methods include proper PHP 8.2+ type hints:
disabled(string|bool|Closure $messageOrCallback = true): RoutegetDisabled(): string|bool|Closure|null- Full PHPDoc annotations for IDE support
License
The MIT License (MIT). Please see License File for more information.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Changelog
Please see CHANGELOG.md for more information on what has changed recently.
All versions of laravel-route-disabling with dependencies
illuminate/routing Version ^11.0|^12.0
illuminate/support Version ^11.0|^12.0
laravel/serializable-closure Version ^2.0