Skip to content
Advertisement

Laravel – Maintenance mode just for some urls

I need to use the Maintenance mode using the artisan command "down", but just for some urls…

In my case, i want that all urls that starts with "/admin/*" continue working.

Is there a solution?

Advertisement

Answer

Suggest by @lukasgeiter I created a middleware that tests my url… That`s my code:

<?php namespace AppHttpMiddleware;

use Closure;
use IlluminateHttpRedirectResponse;

class Maintanance {
    public function handle($request, Closure $next){
        if($request->is('admin*') || $request->is('maintanance')){
            return $next($request);
        }else{
            return new RedirectResponse(url('/maintanance'));
        }
    }
}

After that I created a route that show de maintenance view:

Route::get('maintanance', function(){
    return view('errors.503');
});

Now I can call the command "up" and the application still under maintenance, but the /admin urls…

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement