title: Automate redirection after form validation in Laravel 4
body: <p>I have the following piece of code:</p>
  
  <pre><code>        if(Request::ajax())
          {                    
              $response_values = array(
                  'validation_failed' =&gt; 1,
                  'errors' =&gt; $validator-&gt;errors-&gt;toArray()
              );
              return Response::json($response_values);
          }
          else
          {
              return Redirect::route("resource.create")
                  -&gt;withInput()
                  -&gt;withErrors($validator-&gt;errors);
          }
  </code></pre>
  
  <p>I have this a lot in my code, and would like to find a way to automate this.</p>
  
  <p>I tried creating a method in BaseController but it doesn't redirect properly, I also tried an after filter, but I was unable to pass parameters to this after filter, as I would need to pass errors and route.</p>
  
  <p>How could I achieve this?</p>