2015-04-02 2 views
1

В Laravel 4 вы можете обойти некоторые IP-адрес для режима Laravel Maintenance (php artisan down), делая это:Как обойти некоторые IP-адрес для Laravel 5 Режим обслуживания

App::down(function() 
{ 
    if (!in_array(Request::getClientIp(), ['192.168.0.1'])) 
    { 
     return Response::view('maintenance', [], 503); 
    } 
}); 

Вы также можете предоставить обслуживание конфигурационного файла. PHP со списком всех IP-адресов, чтобы разрешить доступ к приложению в режиме обслуживания:

<?php 

return [ 

    /* 
    |-------------------------------------------------------------------------- 
    | Allowed IP Addresses 
    |-------------------------------------------------------------------------- 
    | Include an array of IP addresses or ranges that are allowed access to the app when 
    | it is in maintenance mode. 
    | 
    | Supported formats: 

    | 
    */ 

    'allowed_ips' => [ 
     '10.0.2.2', 
     '10.2.*.*', 
     '10.0.2.3 - 10.0.2.45', 
     '10.0.3.0-10.3.3.3' 
    ], 

]; 

Мой вопрос, Как я этого добиться в Laravel 5?

ответ

2

Создать новое связующее

<?php 

namespace App\Http\Middleware; 

use Closure; 

use Illuminate\Contracts\Foundation\Application; 

use Illuminate\Http\Request; 

use Symfony\Component\HttpKernel\Exception\HttpException; 



class CheckForMaintenanceMode 

{ 

    protected $request; 

    protected $app; 



    public function __construct(Application $app, Request $request) 

    { 

     $this->app = $app; 

     $this->request = $request; 

    } 



    /** 

    * Handle an incoming request. 

    * 

    * @param \Illuminate\Http\Request $request 

    * @param \Closure $next 

    * @return mixed 

    */ 



    public function handle($request, Closure $next) 

    { 

     if ($this->app->isDownForMaintenance() && 

      !in_array($this->request->getClientIp(), ['::1','another_IP'])) 

     { 

      throw new HttpException(503); 

     } 



     return $next($request); 

    } 

} 

'::1' ваш собственный IP предполагается, что ваш в LocalHost, если не указать свой IP-адрес. Вы можете исключить несколько IP-адресов в массиве. check Excluding your IP Address in Maintenance Mode (php artisan down) in Laravel 5

+0

Хм. круто. спасибо за Ваш ответ. очень полезно. – Digitlimit