I\'m just wondering if anyone know\'s if there\'s a way to activate maintenance mode on a laravel website without using Artisan? I don\'t have command line access to the ser
The real correct answer to question is above provided by Antonio.
You can just call artisan from your application:
Artisan::call('down'); Artisan::call('up');
Since middleware(s) were introduced in Laravel 5, I will cover how I do it in Laravel 5.3 application.
First lets create new middleware $php artisan make:middleware CheckForMaintenanceMode
app = $app;
}
public function handle($request, Closure $next)
{
if ($this->app->isDownForMaintenance() && !$this->isBackendRequest($request)) {
$data = json_decode(file_get_contents($this->app->storagePath() . '/framework/down'), true);
throw new MaintenanceModeException($data['time'], $data['retry'], $data['message']);
}
return $next($request);
}
private function isBackendRequest($request)
{
return ($request->is('admin/*') or $request->is('login'));
}
}
Note: function
isBackendRequest()
which returnstrue
orfalse
if we are either in admin prefix (true
) or trying to login (true
) or anything else (false
)
Open up App/Http/Kernel.php
and rewrite foundations middleware with our new middleware
protected $middleware = [
\App\Http\Middleware\CheckForMaintenanceMode::class,
];
If application is in maintenance mode (down) we can still access login page or any admin/*
page.
Route::group(['middleware' => 'auth', 'prefix' => 'admin'], function () {
//admin routes
});