Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 514
giordanolima Avatar asked Jun 01 '15 11:06

giordanolima


2 Answers

Take a look at app/http/middleware/CheckForMaintenanceMode.php There is a URI Array:

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode as Middleware;

class CheckForMaintenanceMode extends Middleware
{
    /**
     * The URIs that should be reachable while maintenance mode is enabled.
     *
     * @var array
     */
    protected $except = [
        //
    ];
}

array-example :

    protected $except = [
        'api/customers',
        'api/user'
    ];
like image 74
Mario Avatar answered Nov 11 '22 21:11

Mario


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

<?php namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\RedirectResponse;

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...

like image 33
giordanolima Avatar answered Nov 11 '22 20:11

giordanolima