text Laravel维护模式,除了我的IP

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text Laravel维护模式,除了我的IP相关的知识,希望对你有一定的参考价值。

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,
];








以上是关于text Laravel维护模式,除了我的IP的主要内容,如果未能解决你的问题,请参考以下文章

如何绕过 Laravel 5 维护模式的一些 IP 地址

Laravel 5.1 维护模式不起作用

如何使 prestashop 维护模式与动态 IP 一起工作?

维护模式与中间件在 Laravel 中重定向

特定子域上的 Laravel 维护模式

引导模式在 laravel 中不起作用