title: Laravel, can't create object with AJAX request
body: <p>I'm having trouble with Laravel 5.3, in particular, with posting AJAX request data from my JavaScript, I am able to make an object but when i hit save method i get 500 (Internal Server Error).</p>
  
  <p>This is my route:</p>
  
  <pre><code>Route::post('create_comment', 'CommentsController@ajax_store');
  </code></pre>
  
  <p>This is my controller:</p>
  
  <pre><code>public function ajax_store(Request $request)
  {
      $comment = new Comment();
      $comment-&gt;body = $request-&gt;body;
      $comment-&gt;post_id = $request-&gt;post_id;
      $comment-&gt;user_id = auth()-&gt;id();
      $comment-&gt;save();
      return response()-&gt;json(['data' =&gt; $comment]);
  }
  </code></pre>
  
  <p>This is my ajax request:</p>
  
  <pre><code>$('.comment-submit-button').on('click', function(e) {
      e.preventDefault();
      var body = $(this).closest('form').find('textarea').val();
      var post_id = $(this).data();
  
      $.ajax({
          method: 'POST',
          url: urlCreateComment,
          data: {
              body: body,
              post_id: post_id
          }
      }).done(function(data) {
          console.log(data['data']);
      });
  </code></pre>
  
  <p>edit:
  My import is in my index page</p>
  
  <pre><code>@push('scripts')
  &lt;script&gt;
     var urlCreateComment = '{{ url('create_comment') }}';
  &lt;/script&gt;
  
  &lt;script src="{{ asset('/js/realtime.js') }}"&gt;&lt;/script&gt;
  &lt;script&gt;
     $.ajaxSetup({
         headers: {
          'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
         }
      });
  &lt;/script&gt;
  @endpush
  </code></pre>
  
  <p>my form:</p>
  
  <pre><code>&lt;form action="{{ url('create_comment') }}" method="post"&gt;
      &lt;div class="form-group"&gt;
          &lt;textarea placeholder="Write a comment ..." class="form-control" name="body" cols="30" rows="1"&gt;&lt;/textarea&gt;
      &lt;/div&gt;
      &lt;!-- /.form-group --&gt;
      {{ csrf_field()  }}
  
      &lt;div class="form-group adjust"&gt;
          &lt;button data-id="{{ $post-&gt;id }}" type="submit" class="comment-submit-button"&gt;
              &lt;i class="fa fa-caret-right"&gt;&lt;/i&gt;
          &lt;/button&gt;
      &lt;/div&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p>edit: 
  I get this error :
  Array to string conversion (SQL: insert into <code>comments</code> ...</p>
  
  <p>edit: ... i solved it, the problem was that i have to implement the get method on the request...</p>
  
  <pre><code>$request-&gt;get('body');
  </code></pre>
  
  <p>but now i have a new problem when i want to upload an image and i use hasFile() method via ajax with Laravel 5.3 it return null ... why?</p>
  
  <p>Has anybody experience this before? Any insight and advice would really be appreciated. Thank you in advance!</p>