title: Laravel rating data save with ajax
body: <p>I try to save data of post rating with ajax in laravel 5.5</p>
  
  <p>here is my form:</p>
  
  <pre><code> &lt;form class="foodstars" action="{{route('foodStar')}}" id="addStar" method="POST"&gt;
         {{ csrf_field() }}
           &lt;input class="star star-5" value="5" id="star-5" type="radio" name="star"/&gt;
           &lt;label class="star star-5" for="star-5"&gt;&lt;/label&gt;
           &lt;input class="star star-4" value="4" id="star-4" type="radio" name="star"/&gt;
           &lt;label class="star star-4" for="star-4"&gt;&lt;/label&gt;
           &lt;input class="star star-3" value="3" id="star-3" type="radio" name="star"/&gt;
           &lt;label class="star star-3" for="star-3"&gt;&lt;/label&gt;
           &lt;input class="star star-2" value="2" id="star-2" type="radio" name="star"/&gt;
           &lt;label class="star star-2" for="star-2"&gt;&lt;/label&gt;
           &lt;input class="star star-1" value="1" id="star-1" type="radio" name="star"/&gt;
           &lt;label class="star star-1" for="star-1"&gt;&lt;/label&gt;
     &lt;/form&gt;
  </code></pre>
  
  <p>Here is my Ajax:</p>
  
  <pre><code>&lt;script&gt;
  $('#addStar').onclick('.foodstars',function(e) {
    $.ajaxSetup({
              headers: {
                  'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content'),
              }
          });
      e.preventDefault();
      $.ajax({
          type: 'POST',
          cache: false,
          dataType: 'JSON',
          url: '/',
          data: $('#addStar').serialize(),
          success: function(data) {
              console.log(data);
          },
  
      });
      return false;
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>This is my controller:</p>
  
  <pre><code>public function foodStar(){
          // $rating = new Rating;
          // $rating-&gt;rating = 4;
          // $rating-&gt;user_id = \Auth::id();
          // $food-&gt;ratings()-&gt;save($rating);
          $rating = new Rating;
          $rating-&gt;user_id = \Auth::id();
          $rating-&gt;rating = //get new star count;
          $food-&gt;ratings()-&gt;save($rating);
          return response()-&gt;json(['rating' =&gt; $rating-&gt;rating]);
      }
  </code></pre>
  
  <p>and here is my route:</p>
  
  <pre><code>Route::post('/rating', 'FrontendController@foodStar')-&gt;name('foodStar');
  </code></pre>
  
  <p>Default code of my package provided static way to save rates but i need to get what user will select, sample code of package is commented in my controller code.</p>
  
  <p>thanks.</p>