PHPackages                             nikolawd/laravel-route-disabling - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. nikolawd/laravel-route-disabling

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

nikolawd/laravel-route-disabling
================================

Temporarily disable Laravel routes without removing them from the codebase. Originally proposed for Laravel core.

V1.1.0(6mo ago)22MITPHPPHP ^8.2

Since Dec 21Pushed 6mo agoCompare

[ Source](https://github.com/NikolaWd/laravel-route-disabling)[ Packagist](https://packagist.org/packages/nikolawd/laravel-route-disabling)[ RSS](/packages/nikolawd-laravel-route-disabling/feed)WikiDiscussions main Synced today

READMEChangelog (3)Dependencies (5)Versions (4)Used By (0)

Laravel Route Disabling
=======================

[](#laravel-route-disabling)

[![Latest Version on Packagist](https://camo.githubusercontent.com/67899a950370ccce4492adabe5b0cea7bdce614fd7548c61e0d047ad56ef389a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e696b6f6c6177642f6c61726176656c2d726f7574652d64697361626c696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/nikolawd/laravel-route-disabling)[![Total Downloads](https://camo.githubusercontent.com/1c5b1a6e2400cc58424fd0aa37659b75cb16893073f6ecf53cc5651b11bb5d6f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e696b6f6c6177642f6c61726176656c2d726f7574652d64697361626c696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/nikolawd/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
------------

[](#installation)

You can install the package via Composer:

```
composer require nikolawd/laravel-route-disabling
```

The package will automatically register its service provider.

Usage
-----

[](#usage)

### Basic Usage - Default Message

[](#basic-usage---default-message)

```
Route::get('/users', [UserController::class, 'index'])->disabled();
// Returns Laravel's default 503 error page with message: "This route is temporarily disabled."
```

### Custom Message

[](#custom-message)

```
Route::get('/users', [UserController::class, 'index'])
    ->disabled('User management is under maintenance');
// Returns Laravel's 503 error page with your 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.php` in your app
- The `$exception->getMessage()` variable contains your custom message
- Full compatibility with Laravel's exception handling

### Custom Response with Callback

[](#custom-response-with-callback)

```
Route::get('/users', [UserController::class, 'index'])
    ->disabled(function ($request) {
        return response()->json([
            'message' => 'This feature is temporarily unavailable',
            'retry_after' => now()->addHours(2)->timestamp,
        ], 503);
    });
```

### Conditional Disabling

[](#conditional-disabling)

```
Route::get('/beta-feature', [BetaController::class, 'index'])
    ->disabled(config('features.beta_disabled') ? 'Beta features are disabled' : false);
```

### Dynamic Enabling/Disabling

[](#dynamic-enablingdisabling)

Return `null` or `false` from a callback to allow the route to proceed normally:

```
Route::get('/premium-feature', [PremiumController::class, 'index'])
    ->disabled(function ($request) {
        if ($request->user()?->isPremium()) {
            return null; // Allow access for premium users
        }

        return response()->json([
            'message' => 'This feature requires a premium subscription',
        ], 403);
    });
```

Use Cases
---------

[](#use-cases)

### 1. Selective Maintenance Mode

[](#1-selective-maintenance-mode)

Disable specific routes without putting the entire application in maintenance mode:

```
Route::get('/checkout', [CheckoutController::class, 'index'])
    ->disabled('Checkout is temporarily unavailable for system maintenance');
```

### 2. Feature Flags

[](#2-feature-flags)

Easily toggle features on/off based on configuration or environment:

```
Route::get('/new-dashboard', [DashboardController::class, 'new'])
    ->disabled(!config('features.new_dashboard_enabled'));
```

### 3. Time-Based Availability

[](#3-time-based-availability)

Enable routes only during specific time periods:

```
Route::get('/christmas-sale', [SaleController::class, 'christmas'])
    ->disabled(function ($request) {
        $now = now();
        if ($now->between('2025-12-24', '2025-12-26')) {
            return null; // Enable during Christmas
        }
        return 'Christmas sale is only available December 24-26';
    });
```

### 4. Business Hours

[](#4-business-hours)

Restrict access to certain routes during business hours:

```
Route::post('/trading/execute', [TradingController::class, 'execute'])
    ->disabled(function ($request) {
        if (now()->isWeekend() || now()->hour < 9 || now()->hour >= 17) {
            return response()->json([
                'message' => 'Trading is only available 9 AM - 5 PM on weekdays',
            ], 503);
        }
        return null; // Enable during business hours
    });
```

### 5. Gradual Rollouts

[](#5-gradual-rollouts)

Enable features for a percentage of users:

```
Route::get('/new-feature', [FeatureController::class, 'index'])
    ->disabled(function ($request) {
        // Enable for 20% of users based on user ID
        if (($request->user()->id % 5) === 0) {
            return null;
        }
        return 'New feature coming soon!';
    });
```

### 6. Emergency Response

[](#6-emergency-response)

Quickly disable problematic endpoints in production:

```
Route::post('/problematic-endpoint', [ProblematicController::class, 'store'])
    ->disabled('This endpoint is temporarily disabled due to a known issue');
```

Route Caching Support
---------------------

[](#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.

```
# Works perfectly with route caching
php artisan route:cache
```

Testing
-------

[](#testing)

```
composer test
```

Customizing the 503 Error Page
------------------------------

[](#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:

1. Create `resources/views/errors/503.blade.php` in your application
2. Use `$exception->getMessage()` to display your custom message

Example custom error page:

```

    Service Unavailable

    503 - Service Unavailable
    {{ $exception->getMessage() }}
    Back to Home

```

Laravel will automatically use your custom view instead of the default error page.

How It Works
------------

[](#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:

1. The disabled status/message/callback is stored in the route action array
2. A middleware is automatically registered to the route
3. The middleware checks if the route is disabled
4. For simple messages, it calls `abort(503, $message)` which triggers Laravel's error handling
5. If a callback is provided, it's executed and the response is returned
6. If the callback returns `null` or `false`, 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

[](#type-hints)

All methods include proper PHP 8.2+ type hints:

- `disabled(string|bool|Closure $messageOrCallback = true): Route`
- `getDisabled(): string|bool|Closure|null`
- Full PHPDoc annotations for IDE support

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

Changelog
---------

[](#changelog)

Please see [CHANGELOG.md](CHANGELOG.md) for more information on what has changed recently.

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance67

Regular maintenance activity

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

3

Last Release

193d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/115213528?v=4)[Nikola Đorđević](/maintainers/NikolaWd)[@NikolaWd](https://github.com/NikolaWd)

---

Top Contributors

[![NikolaWd](https://avatars.githubusercontent.com/u/115213528?v=4)](https://github.com/NikolaWd "NikolaWd (8 commits)")

---

Tags

laravelroutesmaintenancedisablefeature-flagsRoute Caching

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nikolawd-laravel-route-disabling/health.svg)

```
[![Health](https://phpackages.com/badges/nikolawd-laravel-route-disabling/health.svg)](https://phpackages.com/packages/nikolawd-laravel-route-disabling)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M345](/packages/psalm-plugin-laravel)[illuminate/database

The Illuminate Database package.

2.8k54.9M11.6k](/packages/illuminate-database)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M194](/packages/laravel-ai)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9762.4M131](/packages/roots-acorn)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

77022.3M151](/packages/laravel-mcp)[api-platform/laravel

API Platform support for Laravel

58171.5k14](/packages/api-platform-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
