我希望在Laravel 5.2中为我的所有路线启动状态代码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' => 'WebController@'.$key_underscored ]);
Route::get('/'.$value[$lang].'/{seo_name}/{id}',['as' =>$key_underscored.'_seo_'.$lang, 'uses' => 'WebController@'.$key_underscored]);
Route::get('/404-error', ['as' => 'error404'.'_'.$lang, 'uses' => 'WebController@error404']);
Route::get('/500-error', ['as' => 'error500'.'_'.$lang, 'uses' => 'WebController@error500']);
Route::post('shipping-info-post', ['as' => 'shipping_info_post'.'_'.$lang, 'uses' => 'WebController@shipping_info_post']);
Route::post('payment-post', ['as' => 'payment_post'.'_'.$lang, 'uses' => 'WebController@payment_post']);
Route::post('cart-post', ['as' => 'cart_post'.'_'.$lang, 'uses' => 'WebController@cart_post']);
}
else
{
//echo '/'.$lang.'/'.$value[$lang] . ' as '.$key_underscored.'_'.$lang.' uses '. 'WebController@'.$key_underscored.'<br>';
Route::any('/'.$lang.'/'.$value[$lang],['as' => $key_underscored.'_'.$lang, 'uses' => 'WebController@'.$key_underscored]);
Route::get('/'.$lang.'/'.$value[$lang].'/{seo_name}/{id}',['as' =>$key_underscored.'_seo_'.$lang, 'uses' => 'WebController@'.$key_underscored]);
// generic (not optimized for SEO)
Route::get('/'.$lang.'/404-error', ['as' => 'error404_'.$lang, 'uses' => 'WebController@error404']);
Route::get('/'.$lang.'/500-error', ['as' => 'error500_'.$lang, 'uses' => 'WebController@error500']);
Route::post('/'.$lang.'/shipping-info-post', ['as' => 'shipping_info_post_'.$lang, 'uses' => 'WebController@shipping_info_post']);
Route::post('/'.$lang.'/payment-post', ['as' => 'payment_post_'.$lang, 'uses' => 'WebController@payment_post']);
Route::post('/'.$lang.'/cart-post', ['as' => 'cart_post_'.$lang, 'uses' => 'WebController@cart_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' => 'WebController@index']);
如何在我网站的所有路线上方启动503状态?
答案 0 :(得分:0)
只需在以下文件夹中添加一个名为down
的空文件,您就可以了:/storage/framework/
。
这基本上是php artisan down
在/vendor/laravel/framework/src/Illuminate/Foundation/Console/DownCommand.php
中所做的事情:)
答案 1 :(得分:0)
public function handle($request, Closure $next)
{
return response()->view('503',[], 500);
}
我们必须在视图目录中创建503.blade.php页面以处理请求。
答案 2 :(得分:-1)
创建一个middleware
,返回503
并将其作为一个组应用到您的路线。