title: How do you flash Request data if a Validator fails in Laravel 5?
body: <p>I've created a simple contact form in Laravel 5, using the Request object and a Validator object to check my input for errors.</p>
  <p>The form in my view is coded in HTML, rather than the Laravel Form object, which isn't included by default in Laravel 5.</p>
  <p>I need to set up my form so that if a validation rule fails, the user's input is flashed to the session so it doesn't disappear when the page redirects. I was able to accomplish this by putting a $request-&gt;flash() in the POST controller, before the validation code.</p>
  <p>However, I do not want the data to be flashed (i.e, the form should be reset) if the validation passes and the form is successfully emailed. There's no apparent way for me to accomplish this in the $this-&gt;validate block, since Laravel helpfully handles the redirects automatically.</p>
  <p>How can I tell Laravel to flash the form data ONLY if there is a validation error?</p>
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers;
  
  use Illuminate\Http\Request;
  
  use App\Http\Requests;
  use App\Http\Controllers\Controller;
  
  class ContactController extends Controller
  {
      /**
       * Show the form for creating a new resource.
       *
       * @return Response
       */
      public function create()
      {
          return view('contact');
      }
  
      /**
       * Store a newly created resource in storage.
       *
       * @param Request $request
       * @return Response
       */
      public function store(Request $request)
      {
          // Flash current input in case the validator fails and redirects
          $request-&gt;flash();
  
  // Validate the form request, redirect on fail
          $this-&gt;validate($request, [
              'name' =&gt; 'required',
              'email' =&gt; 'required|email',
              'subject' =&gt; 'required',
              'message' =&gt; 'required|min:5',
          ]);
  
  // Generate email from template and send
          \Mail::send('emails.feedback',
              array(
                  'name' =&gt; $request-&gt;get('name'),
                  'email' =&gt; $request-&gt;get('email'),
                  'user_message' =&gt; $request-&gt;get('message'),
                  'subject' =&gt; $request-&gt;get('subject')
              ), function ($message) use ($request) {
                  $message-&gt;from(\Config::get('site.from_email'));
                  $message-&gt;to(\Config::get('site.contact_email'), 'Admin');
                  $message-&gt;subject(\Config::get('site.name') . ': ' . $request-&gt;get('subject'));
              });
  
  // Redirect to Contact route with success message
          return \Redirect::route('contact')
              -&gt;with('message', 'Thanks for contacting us!');
      }
  }
  
  ?&gt;
  </code></pre>