title: How to flash validation errors to session in Laravel
body: <p>The built in behavior for flashing back validation errors in Laravel does not seem to be working for my use case.</p>
  <p>I have a (React) form that posts it's data via fetch API using this method, which reloads or redirects the page with (hopefully) any session data after the response is returned:</p>
  <pre><code>fetch(props.register_route, {
              method: 'POST',
              headers: {
                  'X-CSRF-Token': props.csrf,
              },
              body: data,
          })
          .then((result) =&gt; {
              return result.json();
          })
          .then((result) =&gt; {
              console.log(result);
              window.location.href = result.url;
          },
          (error) =&gt; {
              console.log(error);
          });
  </code></pre>
  <p>In my controller, I validate this data but if I structure it as follows, the errors are not available as $errors in the resulting page</p>
  <pre><code>if ($validator-&gt;fails()) {
              return redirect()-&gt;back()-&gt;withErrors($validator);
          }
  </code></pre>
  <p>However if I manually flash the errors to the session and return a url instead of a redirect, suddenly the behavior works.</p>
  <pre><code>if ($validator-&gt;fails()) {
              Session::flash('errors', $validator-&gt;errors());
              return response-&gt;json([
                  'url' =&gt; route('register'),
              ], Response::HTTP_NOT_ACCEPTABLE);
          }
  </code></pre>
  <p>I feel as if I must be doing something incorrectly here to have to use this workaround. I could also manually send the errors back in the response, which may be the right way to structure things in the long run.</p>