PHP code example of axvi / laravel-maintenance

1. Go to this page and download the library: Download axvi/laravel-maintenance library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

axvi / laravel-maintenance example snippets


return [
    // Database connection (null = default)
    'connection' => env('MAINTENANCE_DB_CONNECTION', null),

    // Customize table names
    'tables' => [
        'settings' => 'maintenance_settings',
        'ips'      => 'maintenance_ips',
        'tokens'   => 'maintenance_tokens',
    ],

    // Cache maintenance state to avoid DB queries on every request
    'cache' => [
        'enabled' => true,
        'store'   => null,  // null = default cache store
        'ttl'     => 60,    // seconds
    ],

    // URL patterns that should never be blocked by maintenance mode
    'except' => [
        // 'api/health',
        // 'webhook/*',
    ],

    // Bypass route settings
    'bypass_route' => [
        'enabled' => true,
        'prefix'  => 'maintenance',  // GET /maintenance/{token}
    ],

    // Middleware settings
    'middleware' => [
        'cookie_name'     => 'laravel_maintenance',
        'cookie_lifetime' => 43200, // minutes (12 hours)
        'header_name'     => 'X-Maintenance-Token',
    ],

    // Response settings
    'response' => [
        'status'      => 503,
        'retry_after' => 60,
        'refresh'     => null,
        'view'        => 'maintenance::503',
    ],
];

'except' => [
    'api/health',
    'webhook/*',
    'telescope*',
],

'cache' => [
    'enabled' => false,
],

'cache' => [
    'enabled' => true,
    'store'   => 'redis',
    'ttl'     => 30,
],

use Axvi\Maintenance\Facades\Maintenance;

// Check status
Maintenance::isDown();

// Enable / disable
Maintenance::enable([
    'message'     => 'Deploying v2.0',
    'retry_after' => 120,
    'ends_at'     => '2025-01-01 03:00:00',
]);
Maintenance::disable();

// Manage IPs
Maintenance::addIp('192.168.1.1', 'Office', now()->addHours(6));
Maintenance::removeIp('192.168.1.1');

// Manage tokens
Maintenance::addToken('deploy', 'my-secret', now()->addDay());
Maintenance::revokeToken('deploy');

// Full status array
$status = Maintenance::getStatus();

// Flush cache manually
Maintenance::flushCache();

use Axvi\Maintenance\Events\MaintenanceModeEnabled;

Event::listen(MaintenanceModeEnabled::class, function ($event) {
    // Notify the team via Slack, etc.
});
bash
php artisan migrate
bash
php artisan vendor:publish --tag=maintenance-migrations
bash
php artisan vendor:publish --tag=maintenance-config
bash
php artisan vendor:publish --tag=maintenance-views
bash
# Basic
php artisan maintenance:down

# With message, IP whitelist and secret token
php artisan maintenance:down \
  --message="We'll be back in 30 minutes" \
  --allow=192.168.1.1 \
  --secret=my-secret-token \
  --ends-at="2025-01-01 03:00:00"
bash
php artisan maintenance:up
bash
php artisan maintenance:status
bash
php artisan maintenance:ip add 192.168.1.50 --label="Dev machine"
php artisan maintenance:ip add 10.0.0.1 --expires-at="2025-06-01 00:00:00"
php artisan maintenance:ip remove 192.168.1.50
php artisan maintenance:ip list