title: Laravel 5 withError() vs withErrors()
body: <p>I could be doing something very stupid. Accidentally produced a piece of code which I cannot seem to figure out how it works.</p>
  
  <p>I am trying to customize unauthenticated user redirection to login page. So when  user tries to access a page that is protected, laravel redirects the user to the login page. I am trying to show a Javascript toastr message in such cases.</p>
  
  <p>What i did was customize the <code>unauthenticated</code> method in <code>App\Exceptions\Handler.php</code> class as follows:</p>
  
  <pre><code>protected function unauthenticated($request, AuthenticationException $exception)
  {
      if ($request-&gt;expectsJson()) {
          return response()-&gt;json(['error' =&gt; 'Unauthenticated.'], 401);
      }
      //dd($request);
      return redirect()-&gt;guest('login')-&gt;withError('You are not logged in or Your session has expired');
  }
  </code></pre>
  
  <p>Note that i missed the <code>s</code> in the <code>withError</code> function. In my blade file i am showing the toastr notification as follows:</p>
  
  <pre><code>&lt;script&gt;
   @if(Session::has('error'))
  
         toastr.error("{{Session::get('error')}}");
   @endif
   &lt;/script&gt;
  </code></pre>
  
  <p>So whenever a user is being redirected to the login page because he is not logged in yet, a Java Script toastr message is shown. However, i cannot figure out how the <code>Session('error')</code> value is being populated by the <code>withError</code> function. I could only find that Laravel has <code>withErrors</code> function, not <code>withError</code>.</p>
  
  <p>Tried to troubleshoot for last couple hours without luck. Seeking some guidance here. Thanks. Btw, i am very new to Laravel.</p>