PHP code example of edwinylil1 / laravelshoppingcart
1. Go to this page and download the library: Download edwinylil1/laravelshoppingcart library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
Cart::instance('shopping')->add('code', 'Product 1', 1, 9.99);
// Get the content of the 'shopping' cart
Cart::content();
Cart::instance('wishlist')->add('code', 'Product 2', 1, 19.95, 1, ['image' => 'url image']);
// Get the content of the 'wishlist' cart
Cart::content();
// If you want to get the content of the 'shopping' cart again
Cart::instance('shopping')->content();
// And the count of the 'wishlist' cart again
Cart::instance('wishlist')->count();
Cart::store('username');
Cart::instance('custom name')->store('code');
Cart::restore('username');
Cart::instance('custom name')->restore('code');
Cart::content()->count();
Cart::content()->groupBy('id');
// First we'll add the item to the cart.
$cartItem = Cart::add('code', 'Product name', 1, 9.99);
// Next we associate a model with the item.
Cart::associate($cartItem->rowId, 'Product');
// Or even easier, call the associate method on the CartItem!
$cartItem->associate('Product');
// You can even make it a one-liner
Cart::add('code', 'Product name', 1, 9.99)->associate('Product');
// Now, when iterating over the content of the cart, you can access the model.
foreach(Cart::content() as $row) {
echo 'You have ' . $row->qty . ' items of ' . $row->model->name . ' with description: "' . $row->model->description . '" in your cart.';
}