ricadesign / laravel-cart
Laravel shopping Cart
Requires
- php: ^7.1.3|^8.0
- darryldecode/cart: ^4.0
- fideloper/proxy: ^4.4
- laravel/framework: ^8.0 | ^7.0 | ^6.0 | 5.8.*
- laravel/tinker: ^2.5 | ^1.0
This package is auto-updated.
Last update: 2025-03-11 11:56:16 UTC
README
Welcome to the Laravel Cart Package! This package provides a complete solution for adding cart functionality to your Laravel application. It also includes pre-configured endpoints so you can consume the cart quickly and easily.
Installation
You can install this package using Composer. Run the following command in your terminal:
composer require ricadesign/laravel-cart
You can publish the package configurations (useful if you plan to have full control), run the following command:
php artisan vendor:publish --provider="Darryldecode\Cart\CartServiceProvider\LaravelCart\CartServiceProvider" --tag="config"
php artisan vendor:publish --provider="Ricadesign\LaravelCart\LaravelCartServiceProvider" --tag="config"
Configuration
By default, the cart is stored in the user's session. However, if you want to change this configuration to store the cart in the database, you need to add the following line to the config/shopping_cart.php
configuration file:
'storage' => 'Ricadesign\LaravelCart\DBStorage',
After configure storage, you must run:
php artisan migrate
In case you are using DBStorage, you can configure the number of days you want to remain the cart on database in config/laravel-cart.php
configuration file:
'prunable_days' => 14,
In order to clear periodically the database_carts table you can include this line in schedule:
$schedule->command('model:prune', [ '--model' => [DatabaseStorageModel::class], ])->daily();
Endpoints
This package includes a set of pre-configured endpoints that allow you to manage the cart quickly and easily. The endpoints are protected by default authentication, so only authenticated users can perform actions on the cart.
GET /api/cart
: returns the contents of the cart.POST /api/cart
: adds a product to the cart. The request body must include the productid
,name
,price
,quantity
and optionally an array of options.PUT /api/cart
: updates the quantity of a product in the cart.PUT /api/cart/increment
: updates the quantity of a product in the cart.DELETE /api/cart
: removes a product from the cart.
Contributions
If you want to contribute to this package, you can fork the repository on GitHub and send a pull request with your changes. We also appreciate you reporting any issues or bugs you find in the issues section of the repository.