title: Class 'App\Http\Middleware\DB' not found when using Middleware in Laravel 5
body: <p>So I want to check whether the database is connected in laravel 5.I used Middlewares for this.</p>
  
  <p>Middleware code</p>
  
  <p>Middleware.php</p>
  
  <p>namespace App\Http\Middleware;</p>
  
  <pre><code>use Closure;
  
  
  class MyMiddleware {
  
      /**
       * Handle an incoming request.
       *
       * @param  \Illuminate\Http\Request  $request
       * @param  \Closure  $next
       * @return mixed
       */
      public function handle($request, Closure $next)
      {
  
              if(DB::connection()-&gt;getDatabaseName())
              {
                      echo "conncted sucessfully to database ".DB::connection()-&gt;getDatabaseName();
              }else{
                      die("Couldn't connect");
              }
  
  
  
          return $next($request);
      }
  
  }
  </code></pre>
  
  <p>added it to kernel.php</p>
  
  <pre><code>protected $routeMiddleware = [
      'error' =&gt; 'App\Http\Middleware\MyMiddleware',
      'auth' =&gt; 'App\Http\Middleware\Authenticate',
      'auth.basic' =&gt; 'Illuminate\Auth\Middleware\AuthenticateWithBasicAuth',
      'guest' =&gt; 'App\Http\Middleware\RedirectIfAuthenticated',
  ];
  </code></pre>
  
  <p>and I want to check if there is an error in a particular route</p>
  
  <pre><code>Route::get('/wow', ['middleware' =&gt; 'error', function () {
      //
  }]);
  </code></pre>
  
  <p>Every thing works fine for the middleware but no classes or laravel core functions like check db is working.How do I solve it?</p>
  
  <p>This is the error laravel shows</p>
  
  <pre><code>FatalErrorException in MyMiddleware.php line 18:
  Class 'App\Http\Middleware\DB' not found
  </code></pre>