php - Laravel 5 maintenance mode error $app -


i'm configuring maintenance mode in laravel. trying make ip's whitelist. when run code:

<?php  namespace app\http\middleware;  use closure;  class checkformaintenancemode {     /**      * handle incoming request.      *      * @param  \illuminate\http\request  $request      * @param  \closure  $next      * @return mixed      */      public function handle($request, closure $next)      {          if ($this->app->isdownformaintenance() &&              !in_array($request->getclientip(), ['127.0.0.1']))          {              return response('be right back!', 503);          }           return $next($request);      } } 

i error: undefined property: app\http\middleware\checkformaintenancemode::$app

can tell me what's problem ?

you're using $this->app, class doesn't have $app property. can either use app() helper method, can inject application middleware, or can extend laravel's checkformaintenancemode class, take care of you.

extend laravel:

class checkformaintenancemode extends \illuminate\foundation\http\middleware\checkformaintenancemode 

dependency injection:

namespace app\http\middleware;  use closure; use illuminate\contracts\foundation\application;  class checkformaintenancemode {     /**      * application implementation.      *      * @var \illuminate\contracts\foundation\application      */     protected $app;      /**      * create new middleware instance.      *      * @param  \illuminate\contracts\foundation\application  $app      * @return void      */     public function __construct(application $app)     {         $this->app = $app;     }      /**      * handle incoming request.      *      * @param  \illuminate\http\request  $request      * @param  \closure  $next      * @return mixed      */      public function handle($request, closure $next)      {          if ($this->app->isdownformaintenance() &&              !in_array($request->getclientip(), ['127.0.0.1']))          {              return response('be right back!', 503);          }           return $next($request);      } } 

app() helper

 public function handle($request, closure $next)  {      if (app()->isdownformaintenance() &&          !in_array($request->getclientip(), ['127.0.0.1']))      {          return response('be right back!', 503);      }       return $next($request);  } 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

android - Keyboard hides my half of edit-text and button below it even in scroll view -