PHP code example of ismail1k / laravel-cart

1. Go to this page and download the library: Download ismail1k/laravel-cart 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/ */

    

ismail1k / laravel-cart example snippets


  'providers' => [
      Ismail1k\LaravelCart\ServiceProvider::class,
  ],
  'aliases' => [
      'Cart' => Ismail1k\LaravelCart\CartServiceProvider::class,
  ],

use Cart;

$cart = Cart::get($cart_token);

$cart = Cart::create($user_id = null);  //It by default null but if you want to link that created cart to a specified user, You can pass `user_id` parameter.

Cart::add($cart_token, $product_id, $quantity = 1); //The default quantity is 1, that means if you don't specify the quantity, 1 will be added automatically.

Cart::removeItem($product_id);

Cart:clear($cart_token);

Cart::destroy($cart_token);
shell
php artisan vendor:publish --provider="Ismail1k\LaravelCart\ServiceProvider"
shell
php artisan migrate