https://exceptionshub.com/laravel-artisan-down-maintenance-mode-except-own-ip.html
(1) php artisan make:middleware CheckForMaintenanceMode
(2)
<?php namespace App\Http\Middleware;
use Closure;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Http\Request;
use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode as MaintenanceMode;
class CheckForMaintenanceMode {
protected $app;
public function __construct(Application $app)
{
$this->app = $app;
}
public function handle(Request $request, Closure $next)
{
// put your IP or array of IPs here
if ($this->app->isDownForMaintenance() &&
!in_array($request->getClientIp(), ['11.22.33.44']))
{
$maintenanceMode = new MaintenanceMode($this->app);
return $maintenanceMode->handle($request, $next);
}
return $next($request);
}
}
(3) in App\Http\kernel.php:
protected $middleware = [
// \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
\App\Http\Middleware\CheckForMaintenanceMode::class, // Our custom maintenance mode
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
\App\Http\Middleware\TrustProxies::class,
];