title: Laravel: The cart does not contain rowId ce5452f389f041ab17e46324cc050c0d
body: <p>My code works perfect on the local machine, i deployed but the delete, add and update function do not work well that is why i get the following errow "The cart does not contain rowId ce5452f389f041ab17e46324cc050c0d."</p>
  
  <p>Here is my controller</p>
  
  <pre><code>public function index()
      {
          $cartItems=Cart::content();
          return view('cart.index',compact('cartItems'));
      }
  
  
      public function addItem($id)
      {
          $product=Product::find($id);
  
          Cart::add($id,$product-&gt;name,1,$product-&gt;price,['size'=&gt;'medium']);
  
          return back();
      }
  
  
      public function update(Request $request, $id)
      {
  //        dd(Cart::content());
  //        dd($request-&gt;all());
          Cart::update($id,['qty'=&gt;$request-&gt;qty,"options"=&gt;['size'=&gt;$request-&gt;size]]);
          return back();
      }
  
      public function destroy($id)
      {
          Cart::remove($id);
          return back();
      }
  </code></pre>
  
  <p>MY "MODEL" please be patient with me, i only seek understanding if i appear to be some sort of slow</p>
  
  <p>
  
  <pre><code>namespace Gloudemans\Shoppingcart;
  
  use Closure;
  use Illuminate\Support\Collection;
  use Illuminate\Session\SessionManager;
  use Illuminate\Database\DatabaseManager;
  use Illuminate\Contracts\Events\Dispatcher;
  use Gloudemans\Shoppingcart\Contracts\Buyable;
  use Gloudemans\Shoppingcart\Exceptions\UnknownModelException;
  use Gloudemans\Shoppingcart\Exceptions\InvalidRowIDException;
  use Gloudemans\Shoppingcart\Exceptions\CartAlreadyStoredException;
  
  class Cart
  {
      const DEFAULT_INSTANCE = 'default';
  
      /**
       * Instance of the session manager.
       *
       * @var \Illuminate\Session\SessionManager
       */
      private $session;
  
      /**
       * Instance of the event dispatcher.
       * 
       * @var \Illuminate\Contracts\Events\Dispatcher
       */
      private $events;
  
      /**
       * Holds the current cart instance.
       *
       * @var string
       */
      private $instance;
  
      /**
       * Cart constructor.
       *
       * @param \Illuminate\Session\SessionManager      $session
       * @param \Illuminate\Contracts\Events\Dispatcher $events
       */
      public function __construct(SessionManager $session, Dispatcher $events)
      {
          $this-&gt;session = $session;
          $this-&gt;events = $events;
  
          $this-&gt;instance(self::DEFAULT_INSTANCE);
      }
  
      /**
       * Set the current cart instance.
       *
       * @param string|null $instance
       * @return \Gloudemans\Shoppingcart\Cart
       */
      public function instance($instance = null)
      {
          $instance = $instance ?: self::DEFAULT_INSTANCE;
  
          $this-&gt;instance = sprintf('%s.%s', 'cart', $instance);
  
          return $this;
      }
  
      /**
       * Get the current cart instance.
       *
       * @return string
       */
      public function currentInstance()
      {
          return str_replace('cart.', '', $this-&gt;instance);
      }
  
      /**
       * Add an item to the cart.
       *
       * @param mixed     $id
       * @param mixed     $name
       * @param int|float $qty
       * @param float     $price
       * @param array     $options
       * @return \Gloudemans\Shoppingcart\CartItem
       */
      public function add($id, $name = null, $qty = null, $price = null, array $options = [])
      {
          if ($this-&gt;isMulti($id)) {
              return array_map(function ($item) {
                  return $this-&gt;add($item);
              }, $id);
          }
  
          $cartItem = $this-&gt;createCartItem($id, $name, $qty, $price, $options);
  
          $content = $this-&gt;getContent();
  
          if ($content-&gt;has($cartItem-&gt;rowId)) {
              $cartItem-&gt;qty += $content-&gt;get($cartItem-&gt;rowId)-&gt;qty;
          }
  
          $content-&gt;put($cartItem-&gt;rowId, $cartItem);
  
          $this-&gt;events-&gt;fire('cart.added', $cartItem);
  
          $this-&gt;session-&gt;put($this-&gt;instance, $content);
  
          return $cartItem;
      }
  
      /**
       * Update the cart item with the given rowId.
       *
       * @param string $rowId
       * @param mixed  $qty
       * @return \Gloudemans\Shoppingcart\CartItem
       */
      public function update($rowId, $qty)
      {
          $cartItem = $this-&gt;get($rowId);
  
          if ($qty instanceof Buyable) {
              $cartItem-&gt;updateFromBuyable($qty);
          } elseif (is_array($qty)) {
              $cartItem-&gt;updateFromArray($qty);
          } else {
              $cartItem-&gt;qty = $qty;
          }
  
          $content = $this-&gt;getContent();
  
          if ($rowId !== $cartItem-&gt;rowId) {
              $content-&gt;pull($rowId);
  
              if ($content-&gt;has($cartItem-&gt;rowId)) {
                  $existingCartItem = $this-&gt;get($cartItem-&gt;rowId);
                  $cartItem-&gt;setQuantity($existingCartItem-&gt;qty + $cartItem-&gt;qty);
              }
          }
  
          if ($cartItem-&gt;qty &lt;= 0) {
              $this-&gt;remove($cartItem-&gt;rowId);
              return;
          } else {
              $content-&gt;put($cartItem-&gt;rowId, $cartItem);
          }
  
          $this-&gt;events-&gt;fire('cart.updated', $cartItem);
  
          $this-&gt;session-&gt;put($this-&gt;instance, $content);
  
          return $cartItem;
      }
  
      /**
       * Remove the cart item with the given rowId from the cart.
       *
       * @param string $rowId
       * @return void
       */
      public function remove($rowId)
      {
          $cartItem = $this-&gt;get($rowId);
  
          $content = $this-&gt;getContent();
  
          $content-&gt;pull($cartItem-&gt;rowId);
  
          $this-&gt;events-&gt;fire('cart.removed', $cartItem);
  
          $this-&gt;session-&gt;put($this-&gt;instance, $content);
      }
  
      /**
       * Get a cart item from the cart by its rowId.
       *
       * @param string $rowId
       * @return \Gloudemans\Shoppingcart\CartItem
       */
      public function get($rowId)
      {
          $content = $this-&gt;getContent();
  
          if ( ! $content-&gt;has($rowId))
              throw new InvalidRowIDException("The cart does not contain rowId {$rowId}.");
  
          return $content-&gt;get($rowId);
      }
  
      /**
       * Destroy the current cart instance.
       *
       * @return void
       */
      public function destroy()
      {
          $this-&gt;session-&gt;remove($this-&gt;instance);
      }
  
      /**
       * Get the content of the cart.
       *
       * @return \Illuminate\Support\Collection
       */
      public function content()
      {
          if (is_null($this-&gt;session-&gt;get($this-&gt;instance))) {
              return new Collection([]);
          }
  
          return $this-&gt;session-&gt;get($this-&gt;instance);
      }
  
      /**
       * Get the number of items in the cart.
       *
       * @return int|float
       */
      public function count()
      {
          $content = $this-&gt;getContent();
  
          return $content-&gt;sum('qty');
      }
  
      /**
       * Get the total price of the items in the cart.
       *
       * @param int    $decimals
       * @param string $decimalPoint
       * @param string $thousandSeperator
       * @return string
       */
      public function total($decimals = null, $decimalPoint = null, $thousandSeperator = null)
      {
          $content = $this-&gt;getContent();
  
          $total = $content-&gt;reduce(function ($total, CartItem $cartItem) {
              return $total + ($cartItem-&gt;qty * $cartItem-&gt;priceTax);
          }, 0);
  
          return $this-&gt;numberFormat($total, $decimals, $decimalPoint, $thousandSeperator);
      }
  
      /**
       * Get the total tax of the items in the cart.
       *
       * @param int    $decimals
       * @param string $decimalPoint
       * @param string $thousandSeperator
       * @return float
       */
      public function tax($decimals = null, $decimalPoint = null, $thousandSeperator = null)
      {
          $content = $this-&gt;getContent();
  
          $tax = $content-&gt;reduce(function ($tax, CartItem $cartItem) {
              return $tax + ($cartItem-&gt;qty * $cartItem-&gt;tax);
          }, 0);
  
          return $this-&gt;numberFormat($tax, $decimals, $decimalPoint, $thousandSeperator);
      }
  
      /**
       * Get the subtotal (total - tax) of the items in the cart.
       *
       * @param int    $decimals
       * @param string $decimalPoint
       * @param string $thousandSeperator
       * @return float
       */
      public function subtotal($decimals = null, $decimalPoint = null, $thousandSeperator = null)
      {
          $content = $this-&gt;getContent();
  
          $subTotal = $content-&gt;reduce(function ($subTotal, CartItem $cartItem) {
              return $subTotal + ($cartItem-&gt;qty * $cartItem-&gt;price);
          }, 0);
  
          return $this-&gt;numberFormat($subTotal, $decimals, $decimalPoint, $thousandSeperator);
      }
  
      /**
       * Search the cart content for a cart item matching the given search closure.
       *
       * @param \Closure $search
       * @return \Illuminate\Support\Collection
       */
      public function search(Closure $search)
      {
          $content = $this-&gt;getContent();
  
          return $content-&gt;filter($search);
      }
  
      /**
       * Associate the cart item with the given rowId with the given model.
       *
       * @param string $rowId
       * @param mixed  $model
       * @return void
       */
      public function associate($rowId, $model)
      {
          if(is_string($model) &amp;&amp; ! class_exists($model)) {
              throw new UnknownModelException("The supplied model {$model} does not exist.");
          }
  
          $cartItem = $this-&gt;get($rowId);
  
          $cartItem-&gt;associate($model);
  
          $content = $this-&gt;getContent();
  
          $content-&gt;put($cartItem-&gt;rowId, $cartItem);
  
          $this-&gt;session-&gt;put($this-&gt;instance, $content);
      }
  
      /**
       * Set the tax rate for the cart item with the given rowId.
       *
       * @param string    $rowId
       * @param int|float $taxRate
       * @return void
       */
      public function setTax($rowId, $taxRate)
      {
          $cartItem = $this-&gt;get($rowId);
  
          $cartItem-&gt;setTaxRate($taxRate);
  
          $content = $this-&gt;getContent();
  
          $content-&gt;put($cartItem-&gt;rowId, $cartItem);
  
          $this-&gt;session-&gt;put($this-&gt;instance, $content);
      }
  
      /**
       * Store an the current instance of the cart.
       *
       * @param mixed $identifier
       * @return void
       */
      public function store($identifier)
      {
          $content = $this-&gt;getContent();
  
          if ($this-&gt;storedCartWithIdentifierExists($identifier)) {
              throw new CartAlreadyStoredException("A cart with identifier {$identifier} was already stored.");
          }
  
          $this-&gt;getConnection()-&gt;table($this-&gt;getTableName())-&gt;insert([
              'identifier' =&gt; $identifier,
              'instance' =&gt; $this-&gt;currentInstance(),
              'content' =&gt; serialize($content)
          ]);
  
          $this-&gt;events-&gt;fire('cart.stored');
      }
  
      /**
       * Restore the cart with the given identifier.
       *
       * @param mixed $identifier
       * @return void
       */
      public function restore($identifier)
      {
          if( ! $this-&gt;storedCartWithIdentifierExists($identifier)) {
              return;
          }
  
          $stored = $this-&gt;getConnection()-&gt;table($this-&gt;getTableName())
              -&gt;where('identifier', $identifier)-&gt;first();
  
          $storedContent = unserialize($stored-&gt;content);
  
          $currentInstance = $this-&gt;currentInstance();
  
          $this-&gt;instance($stored-&gt;instance);
  
          $content = $this-&gt;getContent();
  
          foreach ($storedContent as $cartItem) {
              $content-&gt;put($cartItem-&gt;rowId, $cartItem);
          }
  
          $this-&gt;events-&gt;fire('cart.restored');
  
          $this-&gt;session-&gt;put($this-&gt;instance, $content);
  
          $this-&gt;instance($currentInstance);
  
          $this-&gt;getConnection()-&gt;table($this-&gt;getTableName())
              -&gt;where('identifier', $identifier)-&gt;delete();
      }
  
      /**
       * Magic method to make accessing the total, tax and subtotal properties possible.
       *
       * @param string $attribute
       * @return float|null
       */
      public function __get($attribute)
      {
          if($attribute === 'total') {
              return $this-&gt;total();
          }
  
          if($attribute === 'tax') {
              return $this-&gt;tax();
          }
  
          if($attribute === 'subtotal') {
              return $this-&gt;subtotal();
          }
  
          return null;
      }
  
      /**
       * Get the carts content, if there is no cart content set yet, return a new empty Collection
       *
       * @return \Illuminate\Support\Collection
       */
      protected function getContent()
      {
          $content = $this-&gt;session-&gt;has($this-&gt;instance)
              ? $this-&gt;session-&gt;get($this-&gt;instance)
              : new Collection;
  
          return $content;
      }
  
      /**
       * Create a new CartItem from the supplied attributes.
       *
       * @param mixed     $id
       * @param mixed     $name
       * @param int|float $qty
       * @param float     $price
       * @param array     $options
       * @return \Gloudemans\Shoppingcart\CartItem
       */
      private function createCartItem($id, $name, $qty, $price, array $options)
      {
          if ($id instanceof Buyable) {
              $cartItem = CartItem::fromBuyable($id, $qty ?: []);
              $cartItem-&gt;setQuantity($name ?: 1);
              $cartItem-&gt;associate($id);
          } elseif (is_array($id)) {
              $cartItem = CartItem::fromArray($id);
              $cartItem-&gt;setQuantity($id['qty']);
          } else {
              $cartItem = CartItem::fromAttributes($id, $name, $price, $options);
              $cartItem-&gt;setQuantity($qty);
          }
  
          $cartItem-&gt;setTaxRate(config('cart.tax'));
  
          return $cartItem;
      }
  
      /**
       * Check if the item is a multidimensional array or an array of Buyables.
       *
       * @param mixed $item
       * @return bool
       */
      private function isMulti($item)
      {
          if ( ! is_array($item)) return false;
  
          return is_array(head($item)) || head($item) instanceof Buyable;
      }
  
      /**
       * @param $identifier
       * @return bool
       */
      private function storedCartWithIdentifierExists($identifier)
      {
          return $this-&gt;getConnection()-&gt;table($this-&gt;getTableName())-&gt;where('identifier', $identifier)-&gt;exists();
      }
  
      /**
       * Get the database connection.
       *
       * @return \Illuminate\Database\Connection
       */
      private function getConnection()
      {
          $connectionName = $this-&gt;getConnectionName();
  
          return app(DatabaseManager::class)-&gt;connection($connectionName);
      }
  
      /**
       * Get the database table name.
       *
       * @return string
       */
      private function getTableName()
      {
          return config('cart.database.table', 'shoppingcart');
      }
  
      /**
       * Get the database connection name.
       *
       * @return string
       */
      private function getConnectionName()
      {
          $connection = config('cart.database.connection');
  
          return is_null($connection) ? config('database.default') : $connection;
      }
  
      /**
       * Get the Formated number
       *
       * @param $value
       * @param $decimals
       * @param $decimalPoint
       * @param $thousandSeperator
       * @return string
       */
      private function numberFormat($value, $decimals, $decimalPoint, $thousandSeperator)
      {
          if(is_null($decimals)){
              $decimals = is_null(config('cart.format.decimals')) ? 2 : config('cart.format.decimals');
          }
          if(is_null($decimalPoint)){
              $decimalPoint = is_null(config('cart.format.decimal_point')) ? '.' : config('cart.format.decimal_point');
          }
          if(is_null($thousandSeperator)){
              $thousandSeperator = is_null(config('cart.format.thousand_seperator')) ? ',' : config('cart.format.thousand_seperator');
          }
  
          return number_format($value, $decimals, $decimalPoint, $thousandSeperator);
      }
  }
  </code></pre>
  
  <p>MY "VIEW"</p>
  
  <pre><code>@foreach($cartItems as $cartItem)
                  &lt;tr&gt;
                      &lt;td style="border-style: solid"&gt;{{$cartItem-&gt;name}}&lt;/td&gt;
                      &lt;td style="border-style: solid"&gt;{{$cartItem-&gt;price}}&lt;/td&gt;
                      &lt;td  style="border-style: solid"&gt;
                          {!! Form::open(['route' =&gt; ['cart.update',$cartItem-&gt;rowId], 'method' =&gt; 'PUT']) !!}
                          &lt;input name="qty" type="text" value="{{$cartItem-&gt;qty}}"&gt;
  
                      &lt;/td&gt;
  
                      &lt;td style="border-style: solid"&gt;
                          &lt;input style="float: left"  type="submit" class="btn btn-success" value="Ok"&gt;
                          {!! Form::close() !!}
                      &lt;/td&gt;
                      &lt;td style="border-style: solid"&gt;
  
                          &lt;form action="{{route('cart.destroy',$cartItem-&gt;rowId)}}"  method="POST" &gt;
                              {{csrf_field()}}
                              {{method_field('DELETE')}}
                              &lt;input class="btn btn-danger" type="submit" value="Delete"&gt;
                          &lt;/form&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
              @endforeach
  </code></pre>
  
  <p>My inspector shows the rowID, i can understand that the rowID is generated by the cart when i add the item but where to located this rowID is something different. </p>
  
  <pre><code>   &lt;tr&gt;
                      &lt;td style="border-style: solid"&gt;ASGHJSDFGHJDF&lt;/td&gt;
                      &lt;td style="border-style: solid"&gt;56&lt;/td&gt;
                      &lt;td  style="border-style: solid"&gt;
                          &lt;form method="POST" action="http://rorisangmaimane.co.za/cart/ce5452f389f041ab17e46324cc050c0d" accept-charset="UTF-8"&gt;&lt;input name="_method" type="hidden" value="PUT"&gt;&lt;input name="_token" type="hidden" value="iXJ3ncGwro7lVA07Mph4rbZloVF1UTQ0m8mlmpK6"&gt;
                          &lt;input name="qty" type="text" value="2"&gt;
  
                      &lt;/td&gt;
  
                      &lt;td style="border-style: solid"&gt;
                          &lt;input style="float: left"  type="submit" class="btn btn-success" value="Ok"&gt;
                          &lt;/form&gt;
                      &lt;/td&gt;
                      &lt;td style="border-style: solid"&gt;
  
                          &lt;form action="http://rorisangmaimane.co.za/cart/ce5452f389f041ab17e46324cc050c0d"  method="POST" &gt;
                              &lt;input type="hidden" name="_token" value="iXJ3ncGwro7lVA07Mph4rbZloVF1UTQ0m8mlmpK6"&gt;
                              &lt;input type="hidden" name="_method" value="DELETE"&gt;
                              &lt;input class="btn btn-danger" type="submit" value="Delete"&gt;
                          &lt;/form&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
  </code></pre>