php artisan down
Oct 7, 2014
24
Level 16
[Laravel 5] Maintenance Mode?
How do I enable maintenance mode in L5? :)
Level 30
@AnthonyIfon you can now create your own middleware for this.
For example create a file at app/Http/Middleware/CheckForMaintenanceMode.php with the following content:
<?php namespace App\Http\Middleware;
use Closure;
use Illuminate\Contracts\Routing\Middleware;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Http\Request;
class CheckForMaintenanceMode implements Middleware {
protected $request;
protected $app;
public function __construct(Application $app, Request $request)
{
$this->app = $app;
$this->request = $request;
}
public function handle($request, Closure $next)
{
if ($this->app->isDownForMaintenance() &&
!in_array($this->request->getClientIp(), ['86.10.190.248', '86.4.7.24']))
{
return response('Be right back!', 503);
}
return $next($request);
}
}
All you have to do is swap the Illuminate's CheckForMaintenanceMode middleware for your implementation, by opening the file app/Http/Kernel.php and replacing line
'Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode'
with
'App\Http\Middleware\CheckForMaintenanceMode'
9 likes
Please or to participate in this conversation.