{"id":14974705,"url":"https://github.com/binafy/laravel-cart","last_synced_at":"2025-05-15T21:05:05.363Z","repository":{"id":242056000,"uuid":"808559170","full_name":"binafy/laravel-cart","owner":"binafy","description":"Laravel Cart is a customizable package for adding shopping cart functionality to Laravel applications","archived":false,"fork":false,"pushed_at":"2025-04-18T13:22:44.000Z","size":153,"stargazers_count":196,"open_issues_count":0,"forks_count":16,"subscribers_count":2,"default_branch":"1.x","last_synced_at":"2025-04-19T02:00:57.769Z","etag":null,"topics":["basket","binafy","cart","e-commerce","laravel","laravel-basket","laravel-cart","laravel-cart-binafy","laravel-cart-package","laravel-framework","milwad","php","shop-cart"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/binafy/laravel-cart","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/binafy.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-31T10:16:04.000Z","updated_at":"2025-04-18T13:22:48.000Z","dependencies_parsed_at":"2024-06-18T07:28:48.281Z","dependency_job_id":"12c3d7d5-5e01-42cf-985a-7a2a9b2ed9e4","html_url":"https://github.com/binafy/laravel-cart","commit_stats":{"total_commits":159,"total_committers":5,"mean_commits":31.8,"dds":"0.037735849056603765","last_synced_commit":"b9e83a85d775b877c574c5887a23f8889b85fbf3"},"previous_names":["binafy/laravel-cart"],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binafy%2Flaravel-cart","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binafy%2Flaravel-cart/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binafy%2Flaravel-cart/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binafy%2Flaravel-cart/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/binafy","download_url":"https://codeload.github.com/binafy/laravel-cart/tar.gz/refs/heads/1.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254422754,"owners_count":22068678,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["basket","binafy","cart","e-commerce","laravel","laravel-basket","laravel-cart","laravel-cart-binafy","laravel-cart-package","laravel-framework","milwad","php","shop-cart"],"created_at":"2024-09-24T13:50:57.846Z","updated_at":"2025-05-15T21:05:05.337Z","avatar_url":"https://github.com/binafy.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Cart\n\n\u003cimg src=\"https://banners.beyondco.de/Laravel%20Cart.png?theme=light\u0026packageManager=composer+require\u0026packageName=binafy%2Flaravel-cart\u0026pattern=autumn\u0026style=style_1\u0026description=customizable+package+for+adding+shopping+cart+functionality+to+Laravel+applications\u0026md=1\u0026showWatermark=0\u0026fontSize=100px\u0026images=https%3A%2F%2Flaravel.com%2Fimg%2Flogomark.min.svg\" alt=\"binafy-laravel-cart\" /\u003e\n\n[![PHP Version Require](https://img.shields.io/packagist/dependency-v/binafy/laravel-cart/php.svg)](https://packagist.org/packages/binafy/laravel-cart)\n[![Latest Stable Version](https://img.shields.io/packagist/v/binafy/laravel-cart.svg)](https://packagist.org/packages/binafy/laravel-cart)\n[![Total Downloads](https://img.shields.io/packagist/dt/binafy/laravel-cart.svg)](https://packagist.org/packages/binafy/laravel-cart)\n[![License](https://img.shields.io/packagist/l/binafy/laravel-cart.svg)](https://packagist.org/packages/binafy/laravel-cart)\n[![Passed Tests](https://github.com/binafy/laravel-cart/actions/workflows/tests.yml/badge.svg)](https://github.com/binafy/laravel-cart/actions/workflows/tests.yml)\n\n- [Introduction](#introduction)\n- [Features](#features)\n- [Installation](#installation)\n- [Publish](#publish)\n- [Usage](#usage)\n    - [Configuration](#configuration)\n    - [Laravel Cart Facade](#laravel-cart-facade)\n      - [Driver](#driver)\n      - [Support Drivers](#support-drivers)\n    - [Laravel Cart Model](#laravel-cart-model)\n      - [Store Cart](#store-cart)\n      - [Access Itemable](#access-itemable)\n      - [Create Cart With Storing Items](#create-cart-with-storing-item)\n      - [Store multiple items](#store-multiple-items)\n      - [Store Item For a Cart](#store-item-for-a-cart)\n      - [Delete Item From Cart](#delete-item-from-cart)\n      - [Delete All Items From Cart](#delete-all-items-from-cart)\n      - [Increase Quantity](#increase-quantity)\n      - [Decrease Quantity](#decrease-quantity)\n    - [Available Events](#available-events)\n- [Contributors](#contributors)\n- [Security](#security)\n- [Changelog](#changelog)\n- [License](#license)\n- [Donate](#donate)\n\n\u003ca name=\"introduction\"\u003e\u003c/a\u003e\n## Introduction\n\nThe `Laravel Cart` is a highly customizable and flexible package that integrates basket functionality into your Laravel application. It simplifies storing and managing cart items, supporting multiple item types and quantities. It is ideal for e-commerce platforms to create carts, attach items, and manage them efficiently. Installation is straightforward via Composer, and it offers robust features like secure item storage, easy cart manipulation, and seamless integration with your existing Laravel app.\n\n\u003ca name=\"features\"\u003e\u003c/a\u003e\n## Features\n\nThe `Laravel Cart` package is an ideal choice for developers looking to implement a reliable and scalable cart system in their Laravel-based e-commerce applications:\n\n- Item Management: Easily add, update, and remove items from the cart with an intuitive API.\n- Attributes and Options: Define custom attributes and options for cart items to handle variations like size and color.\n- Tax Calculation: Built-in support for tax calculations, enabling automatic tax application based on predefined rules.\n- Discounts and Coupons: Integrate discount codes and coupon functionalities to offer promotions and special offers to customers.\n- Session and Database Storage: Flexible storage options allow carts to be stored in sessions or the database.\n- Events and Listeners: Hook into various cart events with listeners to perform actions like logging or triggering additional business logic.\n- Customizable: Extend and customize the core functionalities to meet specific business requirements.\n- Easy Integration: Designed to integrate seamlessly with existing Laravel projects, providing a smooth development experience.\n\n\u003ca name=\"installation\"\u003e\u003c/a\u003e\n## Installation\n\nYou can install the package with Composer:\n\n```bash\ncomposer require binafy/laravel-cart\n```\n\n\u003ca name=\"publish\"\u003e\u003c/a\u003e\n## Publish\n\nIf you want to publish a config file, you can use this command:\n\n```shell\nphp artisan vendor:publish --tag=\"laravel-cart-config\"\n```\n\nIf you want to publish the migrations, you can use this command:\n\n```shell\nphp artisan vendor:publish --tag=\"laravel-cart-migrations\"\n```\n\nFor convenience, you can use this command to publish config, migration, and ... files:\n\n```shell\nphp artisan vendor:publish --provider=\"Binafy\\LaravelCart\\Providers\\LaravelCartServiceProvider\"\n```\n\nAfter publishing, run the `php artisan migrate` command.\n\n\u003ca name=\"usage\"\u003e\u003c/a\u003e\n## Usage\n\n\u003ca name=\"configuration\"\u003e\u003c/a\u003e\n### Configuration\n\nYou can config the `Laravel Cart` with `laravel-cart.php` config that exists in `config` folder.\n\n\u003ca name=\"laravel-cart-facade\"\u003e\u003c/a\u003e\n### Laravel Cart Facade\n\nFor convenience, you can use Laravel Cart facade to store, delete, and ...:\n\n```php\n\u003c?php\n\nuse Binafy\\LaravelCart\\LaravelCart;\n\nLaravelCart::driver('session')-\u003estoreItem($item, $userId|null);\nLaravelCart::storeItem($item $userId|null);\n```\n\n\u003ca name=\"driver\"\u003e\u003c/a\u003e\n### Driver\n\nIf you may to using Laravel Cart facade, you can change the driver for store, delete, and ...:\n\n```php\n\u003c?php\n\nuse Binafy\\LaravelCart\\LaravelCart;\n\nLaravelCart::driver('database')-\u003estoreItem($item, $userId|null);\nLaravelCart::driver('session')-\u003eremoveItem($item);\n```\n\n\u003e The default driver is `database` and if you would to change the driver, you need to use the Laravel Cart config file that exists on `config\\laravel-cart.php`.\n\n\u003ca name=\"support-drivers\"\u003e\u003c/a\u003e\n### Support Drivers\n\n| Drivers  | Name     |\n|----------|----------|\n| Session  | session  |\n| Database | database |\n\n\u003ca name=\"laravel-cart-model\"\u003e\u003c/a\u003e\n### Laravel Cart Model\n\nAlso, you are able to use Laravel Cart models for fetch or ... with Laravel Eloquent.\n\n\u003ca name=\"store-cart\"\u003e\u003c/a\u003e\n### Store Cart\n\nFor storing a new cart, you can use `Cart` model:\n\n```php\nuse \\Binafy\\LaravelCart\\Models\\Cart;\n\n$cart = Cart::query()-\u003efirstOrCreate(['user_id' =\u003e $user-\u003eid]);\n```\n\n\u003ca name=\"access-itemable\"\u003e\u003c/a\u003e\n### Access Itemable\n\nIf you want to access to itemable in `CartItem`, you can use `itemable` relation:\n\n```php\n$cartItem = new CartItem([\n    'itemable_id' =\u003e $itemable-\u003eid,\n    'itemable_type' =\u003e $itemable::class,\n    'quantity' =\u003e 1,\n]);\n\n$cartItem-\u003eitemable()-\u003efirst(); // Return Model Instance\n```\n\n\u003ca name=\"create-cart-with-storing-item\"\u003e\u003ca\u003e\n### Create Cart With Storing Item\n\n\u003e For storing an item for cart, you need to implement `Cartable` interface to your model.\n\n```php\nuse Binafy\\LaravelCart\\Cartable;\n\nclass Product extends Model implements Cartable\n{\n    public function getPrice(): int\n    {\n        //\n    }\n}\n```\n\nAfter, you can store items in multiple ways:\n\n```php\nCart::query()-\u003efirstOrCreateWithStoreItems(\n    item: $product,\n    quantity: 1,\n    userId: $user-\u003eid\n);\n```\n\n\u003ca name=\"store-multiple-items\"\u003e\u003c/a\u003e\n### Store multiple items\n\nIf you may to store multiple items for a cart, you can use `storeItems` method:\n\n```php\n$items = [\n    [\n        'itemable' =\u003e $product1,\n        'quantity' =\u003e 2,\n    ],\n    [\n        'itemable' =\u003e $product2,\n        'quantity' =\u003e 1,\n    ],\n    [\n        'itemable' =\u003e $product3,\n        'quantity' =\u003e 5,\n    ],\n];\n\n$cart = Cart::query()-\u003efirstOrCreate(['user_id' =\u003e $user-\u003eid]);\n$cart-\u003estoreItems($items);\n```\n\n\u003ca name=\"store-item-for-a-cart\"\u003e\u003c/a\u003e\n### Store Item For a Cart\n\nIf you want to store items for cart, first you need to create a cart and attach items to cart:\n\n```php\n$cart = Cart::query()-\u003efirstOrCreate(['user_id' =\u003e $user-\u003eid]);\n$cartItem = new CartItem([\n    'itemable_id' =\u003e $itemable-\u003eid,\n    'itemable_type' =\u003e $itemable::class,\n    'quantity' =\u003e 1,\n]);\n\n$cart-\u003eitems()-\u003esave($cartItem);\n```\n\nIf you may to access the items of one cart, you can use `items` relation that exists in Cart model.\n\nFor conveniences, you can use `storeItem` method. This method take a model or array:\n\n```php\n$cart = Cart::query()-\u003efirstOrCreate(['user_id' =\u003e $user-\u003eid]);\n\n// Model\n$cart-\u003estoreItem($itemable);\n\n// Array\n$item['itemable'] = $itemable;\n$item['quantity'] = 1;\n$cart-\u003estoreItem($item);\n```\n\n\u003ca name=\"delete-item-from-cart\"\u003e\u003c/a\u003e\n### Delete Item From Cart\n\nIf you may to delete an item for a cart, you can use `removeItem` method:\n\n```php\n$items = [\n    [\n        'itemable' =\u003e $product1,\n        'quantity' =\u003e 2,\n    ],\n    [\n        'itemable' =\u003e $product2,\n        'quantity' =\u003e 1,\n    ],\n    [\n        'itemable' =\u003e $product3,\n        'quantity' =\u003e 5,\n    ],\n];\n\n$cart = Cart::query()-\u003efirstOrCreate(['user_id' =\u003e $user-\u003eid]);\n$cart-\u003eremoveItem($product1);\n```\n\n\u003ca name=\"delete-all-items-from-cart\"\u003e\u003c/a\u003e\n### Delete All Items From Cart\n\nIf you may to delete all items from a cart, you can use `emptyCart` method:\n\n```php\n$items = [\n    [\n        'itemable' =\u003e $product1,\n        'quantity' =\u003e 2,\n    ],\n    [\n        'itemable' =\u003e $product2,\n        'quantity' =\u003e 1,\n    ],\n    [\n        'itemable' =\u003e $product3,\n        'quantity' =\u003e 5,\n    ],\n];\n\n$cart = Cart::query()-\u003efirstOrCreate(['user_id' =\u003e $user-\u003eid]);\n$cart-\u003eemptyCart();\n```\n\n\u003ca name=\"increase-quantity\"\u003e\u003c/a\u003e\n### Increase Quantity\n\nIf you may to increase the quantity of item in cart, you can use `increaseQuantity` method:\n\n```php\n$cart-\u003eincreaseQuantity(item: $item, quantity: 2); // By default quantity is 1\n```\n\n\u003ca name=\"decrease-quantity\"\u003e\u003c/a\u003e\n### Decrease Quantity\n\nIf you may to decrease the quantity of item in cart, you can use `decreaseQuantity` method:\n\n```php\n$cart-\u003edecreaseQuantity(item: $item, quantity: 2); // By default quantity is 1\n```\n\n\u003ca name=\"available-events\"\u003e\u003c/a\u003e\n### Available Events\n\nThe `Laravel Cart` have some events that you can listen to these event and doing something:\n\n| Events                             | Description                                                      |\n|------------------------------------|------------------------------------------------------------------|\n| `LaravelCartStoreItemEvent`        | When you store an item in cart, this event fired                 |\n| `LaravelCartRemoveItemEvent`       | When you remove an item from cart, this event fired              |\n| `LaravelCartEmptyEvent`            | When you remove all items from cart, this event fired            |\n| `LaravelCartIncreaseQuantityEvent` | When you increase the quantity of item in cart, this event fired |\n| `LaravelCartDecreaseQuantityEvent` | When you decrease the quantity of item in cart, this event fired |\n\n\u003ca name=\"contributors\"\u003e\u003c/a\u003e\n## Contributors\n\nThanks to all the people who contributed. [Contributors](https://github.com/binafy/laravel-cart/graphs/contributors).\n\n\u003ca href=\"https://github.com/binafy/laravel-cart/graphs/contributors\"\u003e\u003cimg src=\"https://opencollective.com/laravel-cart/contributors.svg?width=890\u0026button=false\" /\u003e\u003c/a\u003e\n\n\u003ca name=\"security\"\u003e\u003c/a\u003e\n## Security\n\nIf you discover any security-related issues, please email `binafy23@gmail.com` instead of using the issue tracker.\n\n\u003ca name=\"chanelog\"\u003e\u003c/a\u003e\n## Changelog\n\nThe changelog can be found in the `CHANGELOG.md` file of the GitHub repository. It lists the changes, bug fixes, and improvements made to each version of the Laravel User Monitoring package.\n\n\u003ca name=\"license\"\u003e\u003c/a\u003e\n## License\n\nThe MIT License (MIT). Please see [License File](https://github.com/binafy/laravel-cart/blob/1.x/LICENSE) for more information.\n\n\u003ca name=\"donate\"\u003e\u003c/a\u003e\n## Donate\n\nIf this package is helpful for you, you can buy a coffee for me :) ❤️\n\n- Iraninan Gateway: https://daramet.com/milwad_khosravi\n- Paypal Gateway: SOON\n- MetaMask Address: `0xf208a562c5a93DEf8450b656c3dbc1d0a53BDE58`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinafy%2Flaravel-cart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbinafy%2Flaravel-cart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinafy%2Flaravel-cart/lists"}