Allow a range of IP addresses to bypass maintenance mode in Laravel

Posted on 4 September 2014

In Laravel, you can put the app in Maintenance Mode by running php artisan down in the console. However, this also locks you out of the app. An easy way to get around this is to do a simple check for an array of allowed IP addresses in app/start/global.php where the Maintenance Mode Handler function exists.

You can take this a step further if you need more advanced functionality to check for IP ranges, which is not feasible with the solution above.

Create a config file maintenance.php to add an array of allowed IP addresses. The array can included a single IP address or a range of IP addresses.

Create a helper file helpers.php in the app folder and add the functions below.

Add the helpers.php file to the bottom of your app/start/global.php file.

require app_path().'/helpers.php'; 

Then just update the Maintenance Mode Handler in app/start/global.php to use the helper function.