PHP code example of lachezargrigorov / laravel-shopping-cart

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

    

lachezargrigorov / laravel-shopping-cart example snippets


\Lachezargrigorov\Cart\CartServiceProvider::class,

'Cart' => \Lachezargrigorov\Cart\Facades\Cart::class,

use Illuminate\Database\Eloquent\Model;
use Lachezargrigorov\Cart\Iterfaces\Item;

class Product extends Model implements Item {}

php artisan vendor:publish --provider="Lachezargrigorov\Cart\CartServiceProvider" --tag="config"
 php
Cart::item($id);  //quantity = 0 on create
 php
Cart::item($id)->remove(); 
 php
Cart::items(); 
 php
Cart::has($id); 
 php
Cart::count(); 
 php
Cart::remove($ids);
 php
Cart::empty();
 php
Cart::isEmpty();
 php
Cart::keys();
 php
Cart::emptyModels();
 php
Cart::condition($name);
 php
Cart::conditions(); 
 php
Cart::hasCondition($name); 
 php
Cart::countConditions(); 
 php
Cart::removeConditions($names);
 php
Cart::emptyConditions();
 php
Cart::isEmptyConditions();
 php
Cart::keysOfConditions();
 php
Cart::totalQuantity();
 php
Cart::subtotalWithoutConditions();
 php
Cart::subtotal();
 php
Cart::total();
 php
Cart::item($id)->quantity(1); 
 php
Cart::item($id)->addQuantity(1); 
 php
Cart::item($id)->quantity; 
 php
Cart::item($id)->attributes(["size" => "L", "color" => "blue"]); 
 php
$attributesCollection = Cart::item($id)->attributes;
$itemSize = $attributesCollection->size;
$itemColor = $attributesCollection->color;

 //or

Cart::item($id)->attributes->size;
Cart::item($id)->attributes->color;

//or using LaravelCollection methods

Cart::item($id)->attributes->has("size");
Cart::item($id)->attributes->get("size");
Cart::item($id)->attributes->each(function($value, $key){
    ...
});
 php
Cart::item($id)->emptyAttributes(); 
 php
Cart::item($id)->condition($name); 
 php
Cart::item($id)->conditions(); 
 php
Cart::item($id)->condition($name)->remove(); 
 php
Cart::item($id)->hasCondition($name); 
 php
Cart::item($id)->isEmptyConditions(); 
 php
Cart::item($id)->emptyConditions(); 
 php
Cart::item($id)->model; 
 php
Cart::item($id)->priceWithoutConditions(); 
 php
Cart::item($id)->priceSumWithoutConditions(); 
 php
Cart::item($id)->price(); 
 php
Cart::item($id)->priceSum();