tsrgtm/maintenance-mode

A Laravel middleware package for maintenance mode

v1.0.0 2025-01-29 16:49 UTC

This package is auto-updated.

Last update: 2025-04-29 01:37:05 UTC


README

A robust solution for managing maintenance mode in Laravel applications with fine-grained control and elegant customization

📖 Table of Contents

  1. Introduction
  2. Key Features
  3. Installation
  4. Configuration
    4.1 Middleware Setup
    4.2 Publishing Assets
    4.3 Configuration Options
  5. Usage
    5.1 Artisan Commands
    5.2 Helper Functions
    5.3 Bypass Mechanism
  6. Customization
  7. Contributing
  8. License
  9. Author

🌟 Introduction

The Laravel Maintenance Mode package provides enterprise-grade maintenance mode management for Laravel applications. Features include environment-based configuration, granular access control, and seamless integration with Laravel's ecosystem.

🚩 Key Features

  • ⚡ Instant toggle via Artisan commands
  • 🔐 Role-based access control
  • 🛣 Route/URL whitelisting
  • 🎭 Customizable maintenance pages
  • 📊 Environment variable sync
  • 👮 Middleware access control
  • 🔍 Real-time status checks

🚀 Installation

composer require tsrgtm/maintenance-mode

🛠 Configuration

Middleware Setup

Global registration (Laravel 11+) in bootstrap/app.php:

use Tsrgtm\MaintenanceMode\Middleware\MaintenanceModeMiddleware;

->withMiddleware(function (Middleware $middleware) {
    $middleware->append(MaintenanceModeMiddleware::class);
})

Route-specific registration:

Route::get('/admin', fn() => view('admin'))->middleware(MaintenanceModeMiddleware::class);

Publishing Assets

php artisan vendor:publish --tag=config
php artisan vendor:publish --tag=views

Configuration Options

config/maintenance.php:

return [
    'enabled' => env('MAINTENANCE_MODE', false),
    'view' => 'maintenance::default',
    'allowed_routes' => ['login', 'status'],
    'allowed_urls' => ['/api/healthcheck'],
];
Option Type Default Description
enabled bool false Maintenance mode status
view string maintenance::default Blade template path
allowed_routes array [] Accessible route names during maintenance
allowed_urls array [] Accessible URL paths during maintenance

🎮 Usage

Artisan Commands

# Toggle maintenance mode
php artisan maintenance:toggle true   # Enable
php artisan maintenance:toggle false  # Disable

# Check status
php artisan maintenance:status

Helper Functions

use Tsrgtm\MaintenanceMode\Helpers\{setMaintenanceMode, isMaintenanceMode};

// Enable maintenance mode
setMaintenanceMode(true);

// Check status
if (isMaintenanceMode()) {
    // Maintenance mode logic
}

Bypass Mechanism

Add to User model:

class User extends Authenticatable
{
    public function canBypassMaintenance(): bool
    {
        return $this->is_admin || $this->hasRole('maintenance-tech');
    }
}

🎨 Customization

  1. Create custom view:
resources/views/vendor/maintenance/custom.blade.php
  1. Update configuration:
'view' => 'vendor.maintenance.custom',

Example view:

@extends('layouts.app') @section('content')
<div class="container">
  <h1>🔧 Scheduled Maintenance</h1>
  <p>We expect to be back by {{ $estimatedTime }}</p>
  <div class="alert alert-info">Contact support: support@example.com</div>
</div>
@endsection

🤝 Contributing

  1. Fork the repository
  2. Create feature branch: git checkout -b feature/new-feature
  3. Commit changes: git commit -m 'Add new feature'
  4. Push to branch: git push origin feature/new-feature
  5. Open Pull Request

📜 License

MIT License - See LICENSE for details.

👤 Author

Tusar Gautam
GitHub ProfileEmail