title: How to pass parameters correctly to a paypal button (laravel)
body: <p>I'm creating a little cart that passes the values of the items you bought to the paypal cart so you can checkout quickly. my problem is that it currently creates a paypal button per item added to the cart. Let me show you.</p>
  <p><a href="https://i.stack.imgur.com/xJ7tr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xJ7tr.png" alt="enter image description here" /></a></p>
  <p>Since there are 3 items in the cart, there are 3 buttons. once you look at the source code, its pretty obvious: the code is inside a @foreach column. My question is, how do I initialize the value $id =&gt; $details so I can pass around the actual values of the products being processed, so the user doesn't need to manually input the products he or she desires? I havent found a way to do this without using the &quot;@foreach&quot; thingy. Let me show you my code:</p>
  <p>this is layout.blade.php:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
      &lt;title&gt;@yield('Carrito')&lt;/title&gt;
      &lt;link rel=&quot;stylesheet&quot; href=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css&quot;&gt;
      &lt;link rel=&quot;stylesheet&quot; href=&quot;https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css&quot;&gt;
      &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;{{ asset('css/style2.css') }}&quot;&gt;
      &lt;script src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js&quot;&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div class=&quot;container&quot;&gt;
      &lt;div class=&quot;row&quot;&gt;
          &lt;div class=&quot;col-lg-12 col-sm-12 col-12 main-section&quot;&gt;
              &lt;div class=&quot;dropdown&quot;&gt;
                  &lt;button type=&quot;button&quot; class=&quot;btn btn-info&quot; data-toggle=&quot;dropdown&quot;&gt;
                      &lt;i class=&quot;fa fa-shopping-cart&quot; aria-hidden=&quot;true&quot;&gt;&lt;/i&gt; Carrito &lt;span class=&quot;badge badge-pill badge-danger&quot;&gt;{{ count((array) session('cart')) }}&lt;/span&gt;
                  &lt;/button&gt;
                  &lt;div class=&quot;dropdown-menu&quot;&gt;
                      &lt;div class=&quot;row total-header-section&quot;&gt;
                          &lt;div class=&quot;col-lg-6 col-sm-6 col-6&quot;&gt;
                              &lt;i class=&quot;fa fa-shopping-cart&quot; aria-hidden=&quot;true&quot;&gt;&lt;/i&gt; &lt;span class=&quot;badge badge-pill badge-danger&quot;&gt;{{ count((array) session('cart')) }}&lt;/span&gt;
                          &lt;/div&gt;
                          &lt;?php $total = 0 ?&gt;
                          @foreach((array) session('cart') as $id =&gt; $details)
                              &lt;?php $total += $details['price'] * $details['quantity'] ?&gt;
                          @endforeach
                          &lt;div class=&quot;col-lg-6 col-sm-6 col-6 total-section text-right&quot;&gt;
                              &lt;p&gt;Total: &lt;span class=&quot;text-info&quot;&gt;$ {{ $total }}&lt;/span&gt;&lt;/p&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                      @if(session('cart'))
                          @foreach(session('cart') as $id =&gt; $details)
                              &lt;div class=&quot;row cart-detail&quot;&gt;
                                  &lt;div class=&quot;col-lg-4 col-sm-4 col-4 cart-detail-img&quot;&gt;
                                      &lt;img src=&quot;{{ $details['photo'] }}&quot; /&gt;
                                  &lt;/div&gt;
                                  &lt;div class=&quot;col-lg-8 col-sm-8 col-8 cart-detail-product&quot;&gt;
                                      &lt;p&gt;{{ $details['name'] }}&lt;/p&gt;
                                      &lt;span class=&quot;price text-info&quot;&gt; ${{ $details['price'] }}&lt;/span&gt; &lt;span class=&quot;count&quot;&gt; Quantity:{{ $details['quantity'] }}&lt;/span&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          @endforeach
                      @endif
                      &lt;div class=&quot;row&quot;&gt;
                          &lt;div class=&quot;col-lg-12 col-sm-12 col-12 text-center checkout&quot;&gt;
                              &lt;a href=&quot;{{ url('cart') }}&quot; class=&quot;btn btn-primary btn-block&quot;&gt;Ver todo&lt;/a&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class=&quot;container page&quot;&gt;
      @yield('content')
  &lt;/div&gt;
  @yield('scripts')
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>and this is cart.blade.php</p>
  <pre><code>@extends('layout')
  @section('title', 'Cart')
  @section('content')
      &lt;table id=&quot;cart&quot; class=&quot;table table-hover table-condensed&quot;&gt;
          &lt;thead&gt;
          &lt;tr&gt;
              &lt;th style=&quot;width:50%&quot;&gt;Producto&lt;/th&gt;
              &lt;th style=&quot;width:10%&quot;&gt;Precio&lt;/th&gt;
              &lt;th style=&quot;width:8%&quot;&gt;Cantidad&lt;/th&gt;
              &lt;th style=&quot;width:22%&quot; class=&quot;text-center&quot;&gt;Subtotal&lt;/th&gt;
              &lt;th style=&quot;width:10%&quot;&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
          &lt;?php $total = 0 ?&gt;
          @if(session('cart'))
              @foreach(session('cart') as $id =&gt; $details)
                  &lt;?php $total += $details['price'] * $details['quantity'] ?&gt;
                  &lt;tr&gt;
                      &lt;td data-th=&quot;Product&quot;&gt;
                          &lt;div class=&quot;row&quot;&gt;
                              &lt;div class=&quot;col-sm-3 hidden-xs&quot;&gt;&lt;img src=&quot;{{ $details['photo'] }}&quot; width=&quot;100&quot; height=&quot;100&quot; class=&quot;img-responsive&quot;/&gt;&lt;/div&gt;
                              &lt;div class=&quot;col-sm-9&quot;&gt;
                                  &lt;h4 class=&quot;nomargin&quot;&gt;{{ $details['name'] }}&lt;/h4&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/td&gt;
                      &lt;td data-th=&quot;Price&quot;&gt;${{ $details['price'] }}&lt;/td&gt;
                      &lt;td data-th=&quot;Quantity&quot;&gt;
                          &lt;input type=&quot;number&quot; value=&quot;{{ $details['quantity'] }}&quot; class=&quot;form-control quantity&quot; /&gt;
                      &lt;/td&gt;
                      &lt;td data-th=&quot;Subtotal&quot; class=&quot;text-center&quot;&gt;${{ $details['price'] * $details['quantity'] }}&lt;/td&gt;
                      &lt;td class=&quot;actions&quot; data-th=&quot;&quot;&gt;
                          &lt;button class=&quot;btn btn-info btn-sm update-cart&quot; data-id=&quot;{{ $id }}&quot;&gt;&lt;i class=&quot;fa fa-refresh&quot;&gt;&lt;/i&gt;&lt;/button&gt;
                          &lt;button class=&quot;btn btn-danger btn-sm remove-from-cart&quot; data-id=&quot;{{ $id }}&quot;&gt;&lt;i class=&quot;fa fa-trash-o&quot;&gt;&lt;/i&gt;&lt;/button&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
  
              @endforeach
          @endif
          &lt;/tbody&gt;
          &lt;tfoot&gt;
          &lt;tr class=&quot;visible-xs&quot;&gt;
              &lt;td class=&quot;text-center&quot;&gt;&lt;strong&gt;Total {{ $total }}&lt;/strong&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;a href=&quot;{{ url('/products') }}&quot; class=&quot;btn btn-warning&quot;&gt;&lt;i class=&quot;fa fa-angle-left&quot;&gt;&lt;/i&gt; Seguir comprando&lt;/a&gt;&lt;/td&gt;
              &lt;td colspan=&quot;2&quot; class=&quot;hidden-xs&quot;&gt;&lt;/td&gt;
              &lt;td class=&quot;hidden-xs text-center&quot;&gt;&lt;strong&gt;Total ${{ $total }}&lt;/strong&gt;&lt;/td&gt;
  
          &lt;!-- the paypal button part --&gt;
  
  
              @if(session('cart'))
              @foreach(session('cart') as $id =&gt; $details)
              &lt;form target=&quot;paypal&quot; action=&quot;https://www.paypal.com/cgi-bin/webscr&quot; method=&quot;post&quot; &gt;
                  &lt;input type=&quot;hidden&quot; name=&quot;cmd&quot; value=&quot;_cart&quot;&gt;
                  &lt;input type=&quot;hidden&quot; name=&quot;business&quot; value=&quot;notanothergenericaddress@gmail.com&quot;&gt;
                  &lt;input type=&quot;hidden&quot; name=&quot;lc&quot; value=&quot;US&quot;&gt;
                  &lt;input type=&quot;hidden&quot; name=&quot;item_name&quot; value=&quot;{{ $details['name'] }}&quot;&gt;
                  &lt;input type=&quot;hidden&quot; name=&quot;amount&quot; value=&quot;{{ $details['price'] }}&quot;&gt;
                  &lt;input type=&quot;hidden&quot; name=&quot;currency_code&quot; value=&quot;MXN&quot;&gt;
                  &lt;input type=&quot;hidden&quot; name=&quot;button_subtype&quot; value=&quot;products&quot;&gt;
                  &lt;input type=&quot;hidden&quot; name=&quot;no_note&quot; value=&quot;0&quot;&gt;
                  &lt;input type=&quot;hidden&quot; name=&quot;tax_rate&quot; value=&quot;15.000&quot;&gt;
                  &lt;input type=&quot;hidden&quot; name=&quot;shipping&quot; value=&quot;500.00&quot;&gt;
                  &lt;input type=&quot;hidden&quot; name=&quot;add&quot; value=&quot;{{ $details['quantity'] }}&quot;&gt;
                  &lt;input type=&quot;hidden&quot; name=&quot;bn&quot; value=&quot;PP-ShopCartBF:btn_cart_LG.gif:NonHostedGuest&quot;&gt;
                  &lt;input type=&quot;image&quot; src=&quot;https://www.paypalobjects.com/es_XC/i/btn/btn_cart_LG.gif&quot; border=&quot;0&quot; name=&quot;submit&quot; alt=&quot;PayPal, la forma más segura y rápida de pagar en línea.&quot;&gt;
                      &lt;img alt=&quot;&quot;  src=&quot;https://www.paypalobjects.com/es_XC/i/scr/pixel.gif&quot; width=&quot;1&quot; height=&quot;1&quot;&gt;
                  &lt;/form&gt;
                  @endforeach
                  @endif
          &lt;/tr&gt;
          &lt;/tfoot&gt;
      &lt;/table&gt;
  </code></pre>