title: Trying to display laravel validation error in axios
body: <p>I am trying to display errors am getting from laravel validation in my app using axios but it keeps displaying this error. The Controller validates the user and any field not filled. it will return an error which will be display on the page using axios.</p>
  
  <p>Error:</p>
  
  <pre><code>VM12049:87 Uncaught (in promise) TypeError: Cannot read property '0' of undefined
  at &lt;anonymous&gt;:87:80
  (anonymous) @ VM12049:87
  XMLHttpRequest.send (async)
  (anonymous) @ VM12045:8
  e.exports @ VM12045:8
  e.exports @ VM12045:8
  Promise.then (async)
  r.request @ VM12045:8
  r.&lt;computed&gt; @ VM12045:8
  (anonymous) @ VM12045:2
  updateProfile @ VM12049:68
  (anonymous) @ VM12049:32
  dispatch @ VM12044:2
  v.handle @ VM12044:2
  </code></pre>
  
  <p>My Code</p>
  
  <p>axios code</p>
  
  <pre><code>  axios.post('/update-student-info', data, {
          "x-csrf-token": $("[name=_token]").val(),
          'content-type': 'multipart/form-data'
      })
          .then(response =&gt; {
              if (response.status === 200) {
                  Swal.fire({
                      title: 'Information Updated',
                      text: '',
                      icon: 'success',
                      confirmButtonText: 'continue',
                      allowOutsideClick: false
                  })
                  $("#profile").val("");
                  $("#update").text("Update");
  
              }
          }).catch(error =&gt; {
  
          first_name_error.text(error.response.data.errors.first_name[0]);
          last_name_error.text(error.response.data.errors.last_name[0]);
          phone_error.text(error.response.data.errors.phone[0]);
          fac_id_error.text(error.response.data.errors.fac_id[0]);
          dept_id_error.text(error.response.data.errors.dept_id[0]);
          console.log(error.response.data.errors);
  
      }).finally(() =&gt; {
          $("#profile_updates").html('Update');
  
      });
  </code></pre>
  
  <p>controller code</p>
  
  <pre><code>    public function updateStudentInfo(Request $request){
      $request-&gt;validate(
           [
              'first_name' =&gt; 'required|string|max:50',
              'last_name' =&gt; 'required|string|max:50',
              'phone' =&gt; 'required',
              'fac_id' =&gt; 'required',
              'dept_id' =&gt; 'required'
          ],[
          'fac_id.required' =&gt; 'This Field is required',
          'dept_id.required' =&gt; 'This Field is required'
      ]);
  
      try {
  
              OtherInstitutionStudents::where('email', Auth::user()-&gt;email)-&gt;update([
                  'first_name' =&gt; $request-&gt;get('first_name'),
                  'last_name' =&gt; $request-&gt;get('last_name'),
                  'phone' =&gt; $request-&gt;get('phone'),
                  'institution_id' =&gt; $request-&gt;get('fac_id'),
                  'institution_level' =&gt; $request-&gt;get('dept_id')
              ]);
  
      } catch (ValidationException $e) {
          return response()-&gt;json([
              'status' =&gt; 'error',
              'msg' =&gt; 'error',
              'errors' =&gt; $e-&gt;errors()
          ], 422);
      }
      return response()-&gt;json($request-&gt;all());
  
  }
  </code></pre>
  
  <p>What should I do?.</p>