masterix21 / laravel-cart
Cart features for any Laravel Project
Fund package maintenance!
masterix21
Requires
- php: ^8.0
- cknow/laravel-money: ^6.1
- illuminate/contracts: ^8.0
- spatie/laravel-package-tools: ^1.4.3
Requires (Dev)
- brianium/paratest: ^6.2
- livewire/livewire: ^2.4
- nunomaduro/collision: ^5.3
- orchestra/testbench: ^6.15
- phpunit/phpunit: ^9.3
- spatie/laravel-ray: ^1.9
- vimeo/psalm: ^4.4
README
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
Installation
You can install the package via composer:
composer require masterix21/laravel-cart
You can publish and run the migrations with:
php artisan vendor:publish --provider="Masterix21\LaravelCart\CartServiceProvider" --tag="laravel-cart-migrations" php artisan migrate
You can publish the config file with:
php artisan vendor:publish --provider="Masterix21\LaravelCart\CartServiceProvider" --tag="laravel-cart-config"
Usage
$product = YourProductModel::first(); // // Add a product to cart $cartItem = Cart::add(label: $product->name, item: $product, price: $product->price, quantity: 1); // // Change the cart item quantity Cart::set($cartItem, 2); // or $cartItem->setQuantity(2); // // Increase the cart item quantity Cart::increase($cartItem); // to increase of 1 Cart::increase($cartItem, 5); // to increase of 5 $cartItem->increase(); // to increase of 1 $cartItem->increase(5); // to increase of 5 // // Decrease the cart item quantity, and if the // quantity is zero, removes the item from the cart. Cart::decrease($cartItem); // to decrease of 1 Cart::decrease($cartItem, 5); // to decrease of 5 $cartItem->decrease(); // to decrease of 1 $cartItem->decrease(5); // to decrease of 5 // Retrieve all cart items $items = Cart::items(); // Clear the cart Cart::clear();
Views using Blade
Display the cart items counter that will auto-refresh on cart changes:
<!-- Automatic refresh the counter --> <livewire:cart-counter /> <!-- Force the displayed value --> <livewire:cart-counter :count="10" no-auto-refresh /> <!-- Customize the component using class argument like so --> <livewire:cart-counter class="text-xs text-white rounded-full bg-red-700" /> <!-- Improve the result by its state --> <livewire:cart-counter class="text-xs rounded-full" empty-class="bg-gray-100 text-gray-500" not-empty-class="bg-red-700 text-white" />
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.