title: laravel add to cart with ajax
body: <p>i am trying to add items to my cart with ajax in laravel but i got error 
  419 (unknown status).</p>
  
  <p>here is my ajax code: </p>
  
  <pre><code>function btnAddCart(param) {
    var product_id = param;
    var url = "{{ route('cart.add') }}";
    $.ajax({
      type: "POST",
      url: url,
      data: { product_id: product_id },
      success: function (data) {
        console.log(data);
  
      },
      error: function (data) {
        console.log('Error:', data);
      }
    });
  };
  </code></pre>
  
  <p>here is my laravel controller function </p>
  
  <pre><code>public function addToCart(Request $request)
  {
      $product = Product::findOrFail($request-&gt;input('product_id'));
      $cart = session()-&gt;has('cart') ? session()-&gt;get('cart') : [];
      if (array_key_exists($product-&gt;id, $cart)) {
          $cart[$product-&gt;id]['quantity']++;
      } else {
          $cart[$product-&gt;id] = [
              'title' =&gt; $product-&gt;title,
              'quantity' =&gt; 1,
              'unit_price' =&gt; $product-&gt;sale_price,
          ];
      }
      session(['cart' =&gt; $cart]);
      session()-&gt;flash('message', $product-&gt;title.' added to cart.');
  
      $data = [];
      $data['cart'] = session()-&gt;has('cart') ? session()-&gt;get('cart') : [];
      return response()-&gt;json($data);
  }
  </code></pre>
  
  <p>so now how do i return json data in ajax success function.</p>