a4anthony/cartavel

电子商务购物车系统

v1.1.1 2021-01-16 19:40 UTC

This package is auto-updated.

Last update: 2024-09-17 03:43:24 UTC


README

Total Downloads Latest Stable Version License

先决条件

要使用此包,用户和商品/库存/产品表迁移文件必须已经设置。

安装步骤

创建新的Laravel应用后,可以使用以下命令包含cartavel包:

composer require a4anthony/cartavel

Laravel ^5.5 使用包自动发现,因此不需要您手动添加ServiceProvider/Facade。

更新composer后,将ServiceProvider添加到config > app.php中的providers数组中

A4anthony\Cartavel\CartavelServiceProvider::class

可选地,您可以使用Facade以缩短代码。将其添加到config > app.php中aliases数组的facades中

"Cartavel" => \A4anthony\Cartavel\Facades\Cartavel::class

为了配置此包以适应您的项目,发布cartavel配置文件

 php artisan vendor:publish --tag=config

转到config > cartavel.php并调整设置以适应您的项目

<?php

return [
    /*
    |--------------------------------------------------------------------------
    | Users Table Name
    |--------------------------------------------------------------------------
    |
    | Here you can specify the users table name.
    |
    */

    'users_table_name' => 'users',

    /*
    |--------------------------------------------------------------------------
    | User Table Unique Column
    |--------------------------------------------------------------------------
    |
    | Here you can specify the unique column to be used from your users table
    |
    */

    'users_table_unique_column' => 'id',

    /*
    |--------------------------------------------------------------------------
    | Cart Table Name
    |--------------------------------------------------------------------------
    |
    | Here you can specify the cart table name.
    |
    */

    'cart_table_name' => 'carts',

    /*
    |--------------------------------------------------------------------------
    | Items/Products Table Name
    |--------------------------------------------------------------------------
    |
    | Here you can specify the table name for your items/products
    |
    */

    'items_table_name' => 'products',

    /*
    |--------------------------------------------------------------------------
    | Items/Products Table Name Unique Column
    |--------------------------------------------------------------------------
    |
    | Here you can specify the unique column to be used from your items/products table
    |
    */

    'items_table_unique_column' => 'id',
];

接下来,确保创建一个新的数据库并将数据库凭证添加到您的.env文件中

DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

运行迁移

php artisan migrate

要使用示例数据填充购物车,需要先填充用户和商品/库存/产品表,然后运行

php artisan cartavel:seed

要使用此包,请导入cartavel包

use A4anthony\Cartavel\Facades\Cartavel;

所有可用方法的列表

Cartavel::get($userId, true); //gets users cart items

Cartavel::add($userId, $itemId, $quantity); //adds item to user's cart

Cartavel::update($userId, $itemId, $quantity); //updates quantity o item in user's cart

Cartavel::delete($userId, $itemId); //deletes item from user's cart

Cartavel::clear($userId); //clears user's cart

享受吧!!!

贡献

欢迎Pull requests。对于重大更改,请首先打开一个问题来讨论您想更改的内容。请确保适当地更新测试。

许可

MIT