2013-07-19 44 views

回答

1

實際上有另一種方式,更直接。正如你在Laravel documentation閱讀,從封閉返回NULL將使Laravel忽略特定請求:

如果封閉傳遞給down方法返回NULL,維護模式將用於該請求被忽略。

因此,對於具有管理員開始的路線,你可以做這樣的事情:

App::down(function() 
{ 
    // requests beginning with 'admin' will bypass 'down' mode 
    if(Request::is('admin*')) { 
    return null; 
    } 

    // all other routes: default 'down' response 
    return Response::view('maintenance', array(), 503); 
}); 
2

我挖了核心,沒辦法做到這一點。 Laravel在app/storage/meta文件夾中檢查名爲down的文件,如果它在那裏,Laravel甚至不會調用路由,它只會顯示錯誤頁面。

這是laravel isDownForMaintenance功能:

public function isDownForMaintenance() 
{ 
    return file_exists($this['path.storage'].'/meta/down'); 
} 

有沒有配置成爲可能。

的另一種方式的laravelish「維護模式」是設置在config/app.php一個新值,添加:

'maintenance' => true, 

然後添加到您的before過濾器:

App::before(function($request) 
{ 
    if(
     Config::get('app.maintenance') && 
     Request::segment(1) != 'admin' // This will work for all admin routes 
     // Other exception URLs 
    ) 
    return Response::make(View::make('hello'), 503); 
}); 

然後就是設置:

'maintenance' => true, 

要回到正常模式