yasinsvr / cart
Laravel shopping cart
Requires
- php: ^8.1
- illuminate/support: ^10.0 || ^11.0 || ^12.0
- illuminate/translation: ^10.0 || ^11.0 || ^12.0
- illuminate/validation: ^10.0 || ^11.0 || ^12.0
Requires (Dev)
- imanghafoori/eloquent-mockery: dev-main
- mockery/mockery: ^1.4.2
- phpunit/phpunit: ^10.0
- symfony/var-dumper: ^5.1
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
π Laravel Shopping Cart
A simple and reusable shopping cart package for Laravel applications.
π About
Laravel Shopping Cart is a lightweight shopping cart package designed for Laravel applications.
The package provides a simple API for managing cart items without requiring a large amount of application-level code.
It can be installed through Composer and integrated into a Laravel application as a reusable package.
β¨ Features
- π Add items to the cart
- π Update cart items
- ποΈ Remove items
- π¦ Retrieve cart contents
- π° Calculate cart totals
- π§© Item attributes and options
- β‘ Simple and reusable API
- π Laravel service provider integration
- π― Facade support
- π§ͺ PHPUnit test structure
- βοΈ Publishable package configuration
π¦ Requirements
- PHP
^8.1 - Laravel
10.x,11.xor12.x
π Installation
Install the package using Composer:
composer require yasinsvr/cart
After installation, Laravel will automatically discover the package.
βοΈ Configuration
If you want to publish the package configuration:
php artisan vendor:publish \
--provider="YasinSVR\Cart\CartServiceProvider" \
--tag="config"
This allows you to customize the package configuration for your application.
π οΈ Basic Usage
Add an Item
use YasinSVR\Cart\Facades\Cart; Cart::add( id: 1, name: 'Product', quantity: 2, price: 150000 );
Get Cart Contents
$items = Cart::content();
Update an Item
Cart::update($rowId, [ 'quantity' => 3, ]);
Remove an Item
Cart::remove($rowId);
Get Cart Total
$total = Cart::total();
The exact method signatures may vary depending on the installed package version. See the source code and tests for the complete API.
π§± Architecture
The package follows a modular package-oriented structure.
src/
βββ Cart.php
βββ CartServiceProvider.php
βββ Facades/
βββ Contracts/
βββ Models/
βββ ...
The package separates cart functionality from the Laravel application itself, making the cart logic reusable across different projects.
π§ͺ Testing
The project includes a PHPUnit test suite.
Run the tests with:
composer test
Or, if PHPUnit is configured directly:
vendor/bin/phpunit
π Supported Laravel Versions
| Laravel | PHP |
|---|---|
| 10.x | ^8.1 |
| 11.x | ^8.1 |
| 12.x | ^8.1 |
π Package
The package is available through Packagist:
yasinsvr/cart
composer require yasinsvr/cart
πΊοΈ Roadmap
Planned improvements may include:
- More complete API documentation
- More usage examples
- Improved test coverage
- Additional cart operations
- Better documentation for advanced use cases
π€ Contributing
Contributions, suggestions and bug reports are welcome.
If you find a bug or have an idea for improving the package, feel free to open an issue or submit a pull request.
π License
This package is open-sourced software licensed under the MIT License.
Made with β€οΈ by Yasin Zolfaghari