title: Laravel 5.5. validation request redirect/response
body: <p>Can I override some property in validation request to control what happens if validation fails? (I don't want to use validation in controller)</p>
  
  <p>I have user validation request:</p>
  
  <pre><code>public function rules()
  {
      return [
          'email'                 =&gt; 'required|email|max:255|unique:user',
          'name'                  =&gt; 'required',
          'password'              =&gt; 'required|min:6',
          'password_confirmation' =&gt; 'required|min:6|same:password'
      ];
  }
  </code></pre>
  
  <p>And when AJAX call is made to register method this happens:</p>
  
  <pre><code>public function postRegisterAjax(UserRegistrationValidationRequest $request)
  {
      ...
      return $this-&gt;responseJson($status, $msg);
  }
  </code></pre>
  
  <p>I need to update <code>$msg</code> somehow so that I can return the validation error message dynamically through JS.</p>
  
  <p><strong>EDIT: my final solution</strong> (in my custom form request)</p>
  
  <pre><code>public function failedValidation(Validator $validator)
  {
      if ($validator-&gt;fails()) {
          $status = Status::ERROR;
          throw new HttpResponseException(response()-&gt;json(["response" =&gt; [
              'msg'    =&gt; $validator-&gt;errors()-&gt;all(':message'),
              'status' =&gt; $status
          ]]));
      }
  
      return response()-&gt;json(["response" =&gt; [
          'msg'    =&gt; 'User successfully registered',
          'status' =&gt; Status::SUCCESS
      ]]);
  }
  </code></pre>