Are you creating an ecommerce site ? or just wanna build a ebay like shopping cart  you can  build your own  shopping  cart very easily using laravel 5.2  . for that we will be using a new laravel  package .

so lets get started with installation

1 – After install Laravel framework, insert on file composer.json, inside require object this value

"syscover/shoppingcart": "dev-master"

and execute on console:

composer update

now you need to register service provider, on file config/app.php add to providers array


next step is to add alias, on file config/app.php add to aliases array

'CartProvider' => Syscover\Shoppingcart\Facades\CartProvider::class,

now you need to To publish package and migrate and execute composer update again:

composer update

The shoppingcart gives you the following methods to use:


 * Add a row to the cart
 * @param string|Array $id      Unique ID of the item|Item formated as array|Array of items
 * @param string       $name    Name of the item
 * @param int          $qty     Item qty to add to the cart
 * @param float        $price   Price of one item
 * @param Array        $options Array of additional options, such as 'size' or 'color'

// Basic form
CartProvider::instance()->add('293ad', 'Product 1', 1, 9.99, array('size' => 'large'));

// Array form
CartProvider::instance()->(['id' => '293ad', 'name' => 'Product 1', 'qty' => 1, 'price' => 9.99, 'options' => array('size' => 'large')]);

// Batch method
  array('id' => '293ad', 'name' => 'Product 1', 'qty' => 1, 'price' => 10.00),
  array('id' => '4832k', 'name' => 'Product 2', 'qty' => 1, 'price' => 10.00, 'options' => array('size' => 'large'))


 * Update the quantity of one row of the cart
 * @param  string        $rowId       The rowid of the item you want to update
 * @param  integer|Array $attribute   New quantity of the item|Array of attributes to update
 * @return boolean
 $rowId = 'da39a3ee5e6b4b0d3255bfef95601890afd80709';

CartProvider::instance()->update($rowId, 2);


CartProvider::instance()->update($rowId, array(‘name’ => ‘Product 1’));

Para hacer correr el testin, hay que usar el siguiente comando:

phpunit tests/CartProviderTest


 * Remove a row from the cart
 * @param  string  $rowId The rowid of the item
 * @return boolean

 $rowId = 'da39a3ee5e6b4b0d3255bfef95601890afd80709';




  • Get a row of the cart by its ID *
  • @param string $rowId The ID of the row to fetch
  • @return CartRowCollection */

$rowId = ‘da39a3ee5e6b4b0d3255bfef95601890afd80709’;




  • Get the cart content *
  • @return CartCollection */




  • Empty the cart *
  • @return boolean */




  • Get the price without shipping *
  • @return float */




  • Get the price total with shipping *
  • @return float */




  • Get the number of items in the cart *
  • @param boolean $totalItems Get all the items (when false, will return the number of rows)
  • @return int */CartProvider::instance()->count(); // Total items CartProvider::instance()->(false); // Total rows



    • Search if the cart has a item *
    • @param Array $search An array with the item ID and optional options
    • @return Array|boolean */

    CartProvider::instance()->search(array(‘id’ => 1, ‘options’ => array(‘size’ => ‘L’))); // Returns an array of rowid(s) of found item(s) or false on failure

CartProvider::instance()->hasShippinh(); CartProvider::instance()->getShippinh(); CartProvider::instance()->setShippinh();


Now the packages also supports multiple instances of the cart. The way this works is like this:

You can set the current instance of the cart with Cart::instance(‘newInstance’), at that moment, the active instance of the cart is newInstance, so when you add, remove or get the content of the cart, you work with the newInstance instance of the cart. If you want to switch instances, you just call Cart::instance(‘otherInstance’) again, and you’re working with the otherInstance again.

So a little example:

CartProvider::instance(‘shopping’)->add(‘192ao12’, ‘Product 1’, 1, 9.99);

// Get the content of the ‘shopping’ cart CartProvider::instance(‘shopping’)->content();

Cart::instance(‘wishlist’)->add(‘sdjk922’, ‘Product 2’, 1, 19.95, array(‘size’ => ‘medium’));

// Get the content of the ‘wishlist’ cart Cart::instance(‘wishlist’)->content();

The default cart instance is called main, so when you’re not using instances, Cart::instance()->content(); is the same as Cart::instance(‘main’)->content().