title: Laravel - Fatal error: Uncaught Error: Class 'Auth' not found
body: <p>I got this Error Message:</p>
  
  <blockquote>
    <p>Fatal error: Uncaught Error: Class 'Auth' not found in F:\projects\websites\main_website\app\Exceptions\Handler.php:65 Stack trace: #0 F:\projects\websites\main_website\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(326): App\Exceptions\Handler->render(Object(Illuminate\Http\Request), Object(Symfony\Component\Debug\Exception\FatalThrowableError)) #1 F:\projects\websites\main_website\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(124): Illuminate\Foundation\Http\Kernel->renderException(Object(Illuminate\Http\Request), Object(Symfony\Component\Debug\Exception\FatalThrowableError)) #2 F:\projects\websites\main_website\public\index.php(56): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request)) #3 {main} thrown in F:\projects\websites\main_website\app\Exceptions\Handler.php on line 65</p>
  </blockquote>
  
  <p>Code its happening on:</p>
  
  <pre><code>$errorLog-&gt;error_happened_to = (Auth::check() ? Auth::user()-&gt;username : 'Guest');
  </code></pre>
  
  <p>Whole class:</p>
  
  <pre><code>&lt;?php
  
  namespace App\Exceptions;
  
  use Exception;
  use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
  use App\Database\Ec9\Website\ErrorLog;
  use Jenssegers\Agent\Agent;
  use Auth;
  
  class Handler extends ExceptionHandler
  {
      /**
       * A list of the exception types that are not reported.
       *
       * @var array
       */
      protected $dontReport = [
          //
      ];
  
      /**
       * A list of the inputs that are never flashed for validation exceptions.
       *
       * @var array
       */
      protected $dontFlash = [
          'password',
          'password_confirmation',
      ];
  
      /**
       * Report or log an exception.
       *
       * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
       *
       * @param  \Exception  $exception
       * @return void
       */
      public function report(Exception $exception)
      {
          parent::report($exception);
      }
  
      /**
       * Render an exception into an HTTP response.
       *
       * @param  \Illuminate\Http\Request  $request
       * @param  \Exception  $exception
       * @return \Illuminate\Http\Response
       */
      public function render($request, Exception $exception)
      {
          if (strlen($exception-&gt;getMessage()) &gt; 0) {
              $agent = new Agent();
              $errorLog = new ErrorLog;
              $errorLog-&gt;error_message = $exception-&gt;getMessage();
              $errorLog-&gt;error_file = $exception-&gt;getFile();
              $errorLog-&gt;error_line = $exception-&gt;getLine();
              $errorLog-&gt;request_ip = $request-&gt;ip();
              $errorLog-&gt;request_url = $request-&gt;root();
              $errorLog-&gt;request_device = $agent-&gt;isDesktop() ? 'Desktop' : ($agent-&gt;isMobile() ? 'Mobile' : 'Tablet');
              $errorLog-&gt;request_system = $agent-&gt;platform() . ' ' . $agent-&gt;version($agent-&gt;platform());
              $errorLog-&gt;request_browser = $agent-&gt;browser();
              $errorLog-&gt;error_happened_to = (Auth::check() ? Auth::user()-&gt;username : 'Guest');
              $errorLog-&gt;save();
          }
  
          return parent::render($request, $exception);
      }
  }
  </code></pre>