2013-07-19 36 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, 

要回到正常模式