2016-08-03 56 views
2

我想爲Laravel 5.2中的所有路由啓動狀態碼503。使用laravel routes.php文件啓動503狀態所有路由

我不能使用'php artisan down'命令。

所以我想在我的文件routes.php中手動執行它。

我嘗試這一點,但不工作:

Route::any('/',function(){#this code not work for me 
    dd('not arrive here'); 
    return abort(503); 
}); 

這是完整的route.php文件:

<?php 


Route::any('/',function(){#this code not work for me 
    dd('not arrive here'); 
    return abort(503); 
}); 

// extra langs 
$conf = Config::get('app.current_site_config'); 
$langs = []; 
$langs[] = $conf['lng_default']; 

if (!empty($conf['lng_extra'])) 
    $langs = array_merge($conf['lng_extra'],$langs); 

$prefix = false; 

if (count($langs) > 1) 
    $prefix = true; 

$pages = Config::get('app.web_config.lang_url'); 

foreach($langs as $lang) 
{  
    foreach($pages as $key=>$value) 
    {  
     $key_underscored = str_replace('-','_',$key); 

     if ($prefix == false) 
     {   
      //echo $key_underscored.'_'.$lang.'<br>'; 
      Route::any('/'.$value[$lang],['as' => $key_underscored.'_'.$lang, 'uses' => '[email protected]'.$key_underscored ]);  
      Route::get('/'.$value[$lang].'/{seo_name}/{id}',['as' =>$key_underscored.'_seo_'.$lang, 'uses' => '[email protected]'.$key_underscored]); 
      Route::get('/404-error', ['as' => 'error404'.'_'.$lang, 'uses' => '[email protected]']); 
      Route::get('/500-error', ['as' => 'error500'.'_'.$lang, 'uses' => '[email protected]']); 
      Route::post('shipping-info-post', ['as' => 'shipping_info_post'.'_'.$lang, 'uses' => '[email protected]_info_post']); 
      Route::post('payment-post', ['as' => 'payment_post'.'_'.$lang, 'uses' => '[email protected]_post']); 
      Route::post('cart-post', ['as' => 'cart_post'.'_'.$lang, 'uses' => '[email protected]_post']); 
     } 
     else 
     { 
      //echo '/'.$lang.'/'.$value[$lang] . ' as '.$key_underscored.'_'.$lang.' uses '. '[email protected]'.$key_underscored.'<br>'; 
      Route::any('/'.$lang.'/'.$value[$lang],['as' => $key_underscored.'_'.$lang, 'uses' => '[email protected]'.$key_underscored]); 
      Route::get('/'.$lang.'/'.$value[$lang].'/{seo_name}/{id}',['as' =>$key_underscored.'_seo_'.$lang, 'uses' => '[email protected]'.$key_underscored]); 

      // generic (not optimized for SEO) 
      Route::get('/'.$lang.'/404-error', ['as' => 'error404_'.$lang, 'uses' => '[email protected]']); 
      Route::get('/'.$lang.'/500-error', ['as' => 'error500_'.$lang, 'uses' => '[email protected]']); 
      Route::post('/'.$lang.'/shipping-info-post', ['as' => 'shipping_info_post_'.$lang, 'uses' => '[email protected]_info_post']); 
      Route::post('/'.$lang.'/payment-post', ['as' => 'payment_post_'.$lang, 'uses' => '[email protected]_post']); 
      Route::post('/'.$lang.'/cart-post', ['as' => 'cart_post_'.$lang, 'uses' => '[email protected]_post']); 
     }  
    } 
} 

if (count($langs) > 1) 
{ 
    Route::get('/',function(){ 
     header('Location: '.route('index_'.Config::get('app.locale')).'/'); 
     exit; 
    }); 
} 
else 
    Route::get('/', ['as' => 'index_'.$langs[0], 'uses' => '[email protected]']); 

如何我可以啓動我的網站的所有路由上面的503狀態?

回答

0

創建一個middleware,返回503並將其作爲一個組應用到您的路線。

+0

如何才能做到這一點? –

+0

Laravel文檔:中間件,隨時問如果oyu有任何問題,當你嘗試實現這一點時 – Vuldo

0

只需在以下文件夾中添加一個名爲down的空文件,您就可以輕鬆前往:​​。

這基本上是什麼php artisan down確實在/vendor/laravel/framework/src/Illuminate/Foundation/Console/DownCommand.php :)