Home > database >  which is the best way for adding maintenance mode in laravel?
which is the best way for adding maintenance mode in laravel?

Time:01-24

i want to add maintenance mode to my cms which i built with laravel, i want to add front part of it, but i don't know which is the best place for checking maintenance mode, in my basic layout file or in a middleware or somewhere else.

consider it that this check should be run on each request on my frontend routes, therefor it needed to be super optimized.

please remind that i want to enable this capability on admin panel of cms, so the admin user doesn't has permission on built in laravel maintenance mode.

and i want it to be okay with a shared host environment. (i have no access to shell commands)

any idea?

i tried to put it on my blade file and in a middleware, but i think it's not optimized.

CodePudding user response:

You could add a Middleware to the Front end routes only. When someone enables maintenance mode in the admin area the middleware could check if maintenance mode is enabled and redirect or show a view

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Auth;

class MaintenanceMode
{
    public function handle($request, Closure $next)
    {
        if (/** Logic Here **/) {
            // Show a diff page
        }

        return $next($request);
    }
}

CodePudding user response:

use the built-in command php artisan down which will disable your application and display a default maintenance page.To bring the application back online, use the command.

php artisan up
  • Related