iori
iori

Reputation: 3506

How to put your Laravel application in maintenance mode and still allow a certain user?

Somewhere in my app/start/global.php I have

App::down(function()
{
    return Response::make("Be right back!", 503);
});

If I did

php artisan down in my cmd my whole site will disable.

I am afraid that I will disables all the visitors including admins.

I don't want that. I still want to allow myself in there because I have to create/upload some contents onto my site.

Is there a way to allow the access to my self and other admin users, but not the clients ?

Thanks

Upvotes: 1

Views: 2070

Answers (1)

user4276926
user4276926

Reputation:

You could store your ip address and other admins ip address in the white listed array of ip addresses, something like this:

App::down(function()
{
    $ip = Request::getClientIp();
    $allowed = array('192.168.1.7', '192.168.1.8', '127.0.0.1');

    if(!in_array($ip, $allowed))
    {
        return Response::view('maintenance', array(), 503);
    }
});

OR

Perform an if else check base on user type

if ( Auth::user()->type == "Admin"){

..... Allow


}else{

..... NOT Allow

}

Upvotes: 3

Related Questions