skip to Main Content

I want launch a status code 503 for all my routes in Laravel 5.2.

I can not use the command ‘php artisan down’.

So I want to do it manually in my file routes.php.

I try with this, but not working:

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

This is the complete route.php file:

<?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']);

How I can launch the 503 state above all routes of my site?

3

Answers


  1. Create a middleware that return a 503 and apply it as a group to your routes.

    Login or Signup to reply.
  2. Just add an empty file called down in the following folder and you’re good to go : /storage/framework/.

    That’s basically what’s php artisan down does in /vendor/laravel/framework/src/Illuminate/Foundation/Console/DownCommand.php 🙂

    Login or Signup to reply.
  3. public function handle($request, Closure $next)
    {
        return response()->view('503',[], 500);
    }
    

    we must create 503.blade.php page in view directory to handle request.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search