title: Ajax post request in laravel 8 return error 500 (Internal Server Error)
body: <p>Am getting Error 500 when posting data through ajax.</p>
  <p><strong>my route</strong></p>
  <pre><code>    Route::group(['as' =&gt;'seller.','prefix'=&gt;'seller','namespace'=&gt;'Seller','middleware'=&gt;['auth','seller']],function(){
  Route::post('/stksubpush','MpesasubscriptionController@make_payment');
  
  });
  </code></pre>
  <p><strong>My controller</strong></p>
  <p>public function make_payment(Request $request)</p>
  <pre><code>    {
             
              $dta['msg']='Successfully';
              return response()-&gt;json($dta);      
              
      }
  </code></pre>
  <p><strong>Blade code</strong></p>
  <pre><code>            @php
              if(url('/') == env('APP_URL')){
                                  
                  $url1 = url('/merchant/stksubpush');
              }
              else{
                                      
              $url1 = url('/seller/stksubpush');
              }
                                  
          @endphp
  
      &lt;form role=&quot;form&quot; id='mpesaform' method=&quot;post&quot; action=&quot;{{ url($url1) }}&quot;&gt;
          @csrf
          @php
           $credentials=json_decode($row-&gt;credentials-&gt;content ?? '');
          @endphp
          &lt;input type=&quot;hidden&quot; name=&quot;plan&quot; value=&quot;{{ $info-&gt;id }}&quot; id='planid'&gt;
          &lt;input type=&quot;hidden&quot; name=&quot;amount&quot; value=&quot;{{ $price }}&quot; id=&quot;amount&quot;&gt;
          &lt;div class=&quot;form-group&quot;&gt;
            &lt;label for=&quot;username&quot;&gt;
            &lt;h6&gt;{{ __('Phone Number') }}&lt;/h6&gt;
           &lt;/label&gt; 
          &lt;input type=&quot;number&quot; name=&quot;phone&quot; placeholder=&quot;Enter Your Phone Number&quot; required 
   class=&quot;form-control &quot; id=&quot;phone&quot;&gt; 
                  &lt;/div&gt;
  
          @if($info-&gt;price &gt; 0)
      &lt;button type=&quot;submit&quot; id='stksubpush' class=&quot;subscribe  btn btn-primary btn-block shadow-sm mt-2  mpesabtn &quot;&gt; Make Payment With {{ $row-&gt;name }} ({{ $price }}) &lt;/button&gt;
      @else
      &lt;a href=&quot;{{ url(env('APP_URL').'/contact') }}&quot; target=&quot;_blank&quot;  class=&quot;subscribe btn btn-primary btn-block shadow-sm text-white&quot;&gt;{{ __('Please Contact With Us') }}&lt;/a&gt;
      @endif
      &lt;/div&gt;
      &lt;/form&gt;
    &lt;script type=&quot;text/javascript&quot;&gt;
    &quot;use strict&quot;;
    
    $(&quot;#mpesaform&quot;).on('submit', function(e){
      e.preventDefault();
      $.ajaxSetup({
        headers: {
          'X-CSRF-TOKEN': $('meta[name=&quot;csrf-token&quot;]').attr('content')
        }
      });
      var basicbtnhtml=$('.mpesabtn').html();
      $.ajax({
        type: 'POST',
        url: this.action,
        data: new FormData(this),
        dataType: 'json',
        contentType: false,
        cache: false,
        processData:false,
     
        beforeSend: function() {
  
          $('.mpesabtn').html(&quot;Please Wait....&quot;);
          $('.mpesabtn').attr('disabled','')
  
        },
        
        success: function(response){ 
          $('.mpesabtn').removeAttr('disabled')
          if (response) {
             console.log(response);
          }
          else{
            console.log('Error ocured');
          }
          
        },
  
      })
  
  
    });
  
  
  &lt;/script&gt;
  </code></pre>
  <p>but it gives me an error when I run the console in google chrome and it doesn't return the expected response &quot;return 'Successfully.</p>
  <p>Request URL: <a href="https://rivan.scriptsale.xyz/seller/stksubpush" rel="nofollow noreferrer">https://rivan.scriptsale.xyz/seller/stksubpush</a>
  Request Method: POST
  Status Code: 500
  Remote Address: 145.239.3.48:443
  Referrer Policy: strict-origin-when-cross-origin</p>