PHPackages                             misterphilip/maintenance-mode - 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. misterphilip/maintenance-mode

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

misterphilip/maintenance-mode
=============================

An enhanced drop-in replacement for Laravel's maintenance mode

2.0.1(6y ago)120176.7k↓47.8%21MITPHPPHP &gt;=7.0.0

Since Jul 2Pushed 6y ago9 watchersCompare

[ Source](https://github.com/awjudd/maintenance-mode)[ Packagist](https://packagist.org/packages/misterphilip/maintenance-mode)[ RSS](/packages/misterphilip-maintenance-mode/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (2)Versions (17)Used By (0)

Enhanced Laravel Maintenance Mode
=================================

[](#enhanced-laravel-maintenance-mode)

This package is a drop-in replacement for Laravel's maintenance mode. The following versions are supported:

- Laravel 5.0 - 5.2, please use the [1.0 branch](https://github.com/MisterPhilip/maintenance-mode/tree/1.0).
- There are currently no plans to support Laravel 5.3 - 5.4.
- Laravel 5.5 - 5.8, please use the [1.3 branch](https://github.com/MisterPhilip/maintenance-mode/tree/1.3)
- Laravel 6.0, please use the [2.0 branch](https://github.com/MisterPhilip/maintenance-mode/tree/2.0). Note that 5.5+ *can* work with the 2.0 branch, but it is not guaranteed to be backwards compatible.

Features include:

- Allowing custom maintenance messages to be shown to users
- Including a timestamp of when the application went down
- Exempting select users via custom exemption classes
- Firing an event for when the application goes down
- Dynamically selecting the view to be shown on down command

Table of Contents
-----------------

[](#table-of-contents)

1. [Installation](#installation)
2. [Changes from 1.0](#changes-from-1.0)
3. [Usage](#usage)
4. [Configuration](#configuration)1. [Default Configuration](#default-configuration)1. [Overriding Defaults](#overriding-defaults)
5. [Exemptions](#exemptions)1. [Default Exemptions](#default-exemptions)
    1. [IP Whitelist](#ip-whitelist)
    2. [Environment Whitelist](#environment-whitelist)1. [Creating a New Exemption](#creating-a-new-exemption)
6. [Views](#views)1. [Application Down](#application-down)1. [Maintenance Notification](#maintenance-notification)
7. [Events](#events)

Installation
------------

[](#installation)

Run the following command to install the latest:

```
$ composer require "misterphilip/maintenance-mode:~2.0"
```

Or, if you prefer installing it manually, within `composer.json` add the following line to the end of the `require` section:

```
"misterphilip/maintenance-mode": "~2.0"
```

And then run the Composer install command:

```
$ composer install
```

Laravel *should* automatically install the Service Providers, but verify they exist within the `config/app.php` file. If they do not, add `MisterPhilip\MaintenanceMode\MaintenanceModeServiceProvider::class,` and `MisterPhilip\MaintenanceMode\MaintenanceCommandServiceProvider::class,` to the end of the `$providers` array in your `config/app.php`:

```
'providers' => [

    /*
     * Application Service Providers...
     */
     App\Providers\AppServiceProvider::class,
     App\Providers\EventServiceProvider::class,
     App\Providers\RouteServiceProvider::class,

     ...

     MisterPhilip\MaintenanceMode\MaintenanceModeServiceProvider::class,
     MisterPhilip\MaintenanceMode\MaintenanceCommandServiceProvider::class,
],
```

Finally, in `app/Http/Kernel.php` replace the current MaintenanceMode Middleware

```
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
```

with

```
\MisterPhilip\MaintenanceMode\Http\Middleware\CheckForMaintenanceMode::class,
```

Changes from 1.0
----------------

[](#changes-from-10)

Since Laravel 5.3, messages are now allowed in the default `artisan down` command, as well as adding an option for the `Retry-After` HTTP header. Because of this it should be noted that the syntax to call the `artisan down` command has changed from the 1.0 branch to better match Laravel's default command.

Additionally, we've changed the `MaintenanceModeEnabled` event to no longer use the `info` property, but instead have separate properties for each piece of information. See more in the [events section](#events).

Usage
-----

[](#usage)

This package overwrites the default `artisan down` command, with more options:

```
$ php artisan down [--message=MESSAGE] [--retry=RETRY] [--view=VIEW] [--allow*=ALLOW]
```

For example,

```
$ php artisan down --message="We're currently upgrading our system! Please check back later."
```

would show users a message of "We're doing some routine maintenance! Be back soon!". If you don't pass in a message, the default "We're currently working on the site, please try again later" will display to the users. Of course this default is configurable via a language string.

You can also change the view that is shown each time you run the `artisan down` command via the `--view=[VIEW]` option:

```
$ php artisan down --message="Be back in a few!" --view="errors/maintenance"
```

And of course you can use the default `--retry` option as well:

```
$ php artisan down --message="Be back in a few!" --view="errors/maintenance" --retry=60
```

To bring your application back online, run the normal app up command:

```
$ php artisan up
```

**NOTE:** by default, two [exemptions](#exemptions) enabled, which means that if you run your development server locally (127.0.0.1) *or* you have `APP_ENV=local` in your `.env` file, you will *not* see the maintenance page. You can remove these exemptions via the [configuration](#overriding-defaults).

Configuration
-------------

[](#configuration)

This package is a drop-in replacement for the default maintenance mode provided with Laravel 5. This means that you do not have to do any configuration out-of-the-box. However, if you'd like to tweak some of the settings, there are a number of configuration values that are available to make this package a better fit for your application.

### Default Configuration

[](#default-configuration)

Below are the default configuration options and a short description on each. Don't worry, all of this information is within the configuration file too!

- `view` (string)
    - The view to show to users when maintenance mode is currently enabled. This can be temporarily overridden when the command is called via the `--view` option
    - Defaults to `maintenancemode::app-down`
- `notification-styles` (boolean)
    - Include CSS styling with the optional [maintenance notification](#maintenance-notification) view
    - Defaults to `true`
- `inject.global` (boolean)
    - Enable or disable global visibility to maintenance mode variables (accessible in all views)
    - Defaults to `true`
- `inject.prefix` (string)
    - Prefix the maintenance mode variables to prevent view variable name collisions
    - Defaults to `MaintenanceMode`
- `language-path` (string)
    - The path to the maintenance mode language strings.
    - Defaults to `maintenancemode::defaults`
- `exempt-ips` (string array)
    - An array of IP address that will always be exempt from the application down page
    - Defaults to `['127.0.0.1']`
- `exempt-ips-proxy` (boolean)
    - Use [proxies](http://symfony.com/doc/current/components/http_foundation/trusting_proxies.html)to get the user's IP address
    - Defaults to `false`
- `exempt-environments` (string array)
    - An array of environment names that will always be exempt from the application down page
    - Defaults to `['local']`
- `exemptions` (string array)
    - A list of the exemption classes to execute. *See [Exemptions](#exemptions)*
    - Defaults to:

```
    '\MisterPhilip\MaintenanceMode\Exemptions\IPWhitelist',
    '\MisterPhilip\MaintenanceMode\Exemptions\EnvironmentWhitelist',
```

### Overriding Defaults

[](#overriding-defaults)

If you need to override the default configuration values, run the following command:

```
$ php artisan vendor:publish --provider="MisterPhilip\MaintenanceMode\MaintenanceModeServiceProvider" --tag="config"
```

Now you can edit the values at `config/maintenancemode.php`.

Exemptions
----------

[](#exemptions)

Exemptions allow for select users to continue to use the application like normal based on a specific set of rules. Each of these rule sets are defined via a class which is then executed against.

### Default Exemptions

[](#default-exemptions)

By default, an IP whitelist and an application environment whitelist are included with this package to get you off the ground running. Additionally, more examples are provided for various types of exemptions that might be useful to your application.

##### IP Whitelist

[](#ip-whitelist)

This exemption allows you to check the user's IP address against a whitelist. This is useful for always including your office IP(s) so that your staff doesn't see the maintenance page. This is similar to the `allow` option that is offered in Laravel 5.6+ (and is backported to 5.5 with this package), however the `allow` option requires you to pass the IPs every time, vs. this method allows for you to have IPs stored in the configuration. Both methods can be used with each other, e.g. a static internal network should always be allowed via the config, while an additional IP for a vendor or remote employee can temporarily be added via the `allow` option.

Configuration values included with this exemption are:

- `exempt-ips` - An array of IP addresses that will not see the maintenance page
- `exempt-ips-proxy` - Set to `true` if you have IP proxies setup

##### Environment Whitelist

[](#environment-whitelist)

This exemption allows you to check if the current environment matches against a whitelist. This is useful for local development where you might not want to see the maintenance page.

Configuration values included with this exemption are:

- `exempt-environments` - An array of environments that will not display the maintenance page

### Creating a new exemption

[](#creating-a-new-exemption)

Setting up a new exemption is simple:

1. Create a new class and extend `MisterPhilip\MaintenanceMode\Exemptions\MaintenanceModeExemption`. You might consider creating these files in `app\Exemptions` or `app\Infrastructure\Maintenance`, but you're free to place them where you want.
2. This class must include an `isExempt` method. This method should return `true` if the user should not see the maintenance page. If this returns `false`, it indicates that the user does not match your ruleset and other exceptions should be checked.
3. Add the full class name to the `exemptions` array in the configuration file.

Below is an template to use for a new exemption class `SampleExemption`:

```
