title: how to make validation using ajax Laravel 5.3
body: <p>I am using Laravel 5. In my OrganisationsController I have a method addItem</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code> public function addItem(Request $request)
      {
          $rules = array(
              'nom' =&gt; 'required',
          );
          // for Validator
          $validator = Validator::make(Input::all(), $rules);
          if ($validator-&gt;fails())
              return Response::json(array('errors' =&gt; $validator-&gt;getMessageBag()-&gt;toArray()));
  
          else {
              $section = new Section();
              $section-&gt;nom = $request-&gt;nom;
              $section-&gt;save();
              return response()-&gt;json($section);
          }
      }</code></pre>
  </div>
  </div>
  </p>
  
  <blockquote>
    <p>Ajax code </p>
  </blockquote>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>    $("#add").click(function() {
              $.ajax({
                  type: 'post',
                  url: '/addItem',
                  data: {
                      '_token': $('input[name=_token]').val(),
                      'nom': $('input[name=nom]').val()
                  },
                  success: function(data) {
                      if ((data.errors)) {
                          $('.error').removeClass('hidden');
                          $('.error').text(data.errors.title);
                          $('.error').text(data.errors.description);
                      } else {
                          $('.error').remove()
                          $('table').append("&lt;tr class='section" + data.id + "'&gt;&lt;td&gt;" + data.id + "&lt;/td&gt;&lt;td&gt;" + data.nom + "&lt;/td&gt;&lt;td&gt;&lt;button class='edit-modal btn btn-info' data-id='" + data.id + "' data-nom='" + data.nom + "'&gt;&lt;span class='glyphicon glyphicon-edit'&gt;&lt;/span&gt; Edit&lt;/button&gt; &lt;button class='delete-modal btn btn-danger' data-id='" + data.id + "' data-nom='" + data.nom +  "'&gt;&lt;span class='glyphicon glyphicon-trash'&gt;&lt;/span&gt; Delete&lt;/button&gt;&lt;/td&gt;&lt;/tr&gt;"); }
                     }
                  });
  
              $('#noom').val('');
          });</code></pre>
  </div>
  </div>
  </p>
  
  <blockquote>
    <p>html code</p>
  </blockquote>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="form-group row add"&gt;
      &lt;div class="col-md-5"&gt;
          &lt;input type="text" class="form-control " id="noom" name="nom"
                 placeholder="New section here" required&gt;
    &lt;p class="error text-center alert alert-danger hidden"&gt;&lt;/p&gt;
      &lt;/div&gt;
      &lt;div class="col-md-2"&gt;
          &lt;button class="btn btn-warning" type="submit" id="add"&gt;
              &lt;span class="glyphicon glyphicon-plus"&gt;&lt;/span&gt; Add new Section
          &lt;/button&gt;
      &lt;/div&gt;
  
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I don't know why my validation not work. Please suggest a example for this. I am using laravel 5. I have searched so many sites. But I cannot get solution for this.</p>