Laravel-工匠下来/维护模式,除了自己的IP [英] Laravel - artisan down / Maintenance Mode except own IP
本文介绍了Laravel-工匠下来/维护模式,除了自己的IP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目前,我正在使用Laravel5. 我的问题是,如果我将维护模式与
Currently i am using Laravel5. My question is if if i use the Maintenance mode with
php artisan down
如何说除了我自己的IP之外,每个人的应用程序都关闭了"? 因此,每个人都看到了维护模式,但是我仍然可以访问该网站.
how can say "the application is down for everyone except my own ip" ? So everyone is seeing the Maintenance mode, but i have still access to the site.
推荐答案
在Laravel 5中,您必须创建自己的中间件. 在app/Http/Middleware/CheckForMaintenanceMode.php中创建文件 您当然可以选择任何文件名.
In Laravel 5 you have to create your own middleware. Create a file in app/Http/Middleware/CheckForMaintenanceMode.php You can choose of course any filename.
<?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)
{
if ($this->app->isDownForMaintenance() &&
!in_array($request->getClientIp(), ['8.8.8.8', '8.8.4.4']))
{
$maintenanceMode = new MaintenanceMode($this->app);
return $maintenanceMode->handle($request, $next);
}
return $next($request);
}
}
在您的app/Http/Kernel.php中更改
In your app/Http/Kernel.php change
'Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode'
到
'App\Http\Middleware\CheckForMaintenanceMode'
这篇关于Laravel-工匠下来/维护模式,除了自己的IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文