Laravel 6.15 是否与任何购物车包兼容?

Is Laravel 6.15 compatible with any shopping cart package?

我正在尝试为一个大学项目开发​​一个基于 Laravel 的电子商务,没什么特别的,它不会发布。
前提:我是一名学生和初学者,对于我的任何错误,我深表歉意。我正在使用 Laravel 6.15.

我制作了一个非常基本的HTML+CSS模板并为电子商务建立了一个自定义数据库,加载了一些记录只是为了测试目的:一切正常(显示产品,数据正确,无错误)。我必须建立一个购物车才能让最终用户购买东西,但尽管尝试了几个包裹,我还是无法将商品添加到我的购物车。

这是我尝试过的:

我的代码如下(截至上次更新,所以这里我使用的是 Treestoneit 的购物车)。

CartController.php

use Illuminate\Http\Request;
use App\Product;
use Treestoneit\ShoppingCart\Facades\Cart;
...
public function store(Request $request)
    {
    $product = Product::findOrFail($request->id);
    Cart::add($product, 1);
    return redirect()->route('cart.index')->with('success_message', 'Item added to cart successfully!');
}

product.blade.php

<form action="{{ route('cart.store', $product) }}" method="POST">
    {{ csrf_field() }}
    <button type="submit" class="btn btn-primary">Add to cart!</button>
</form>

($product 被正确检索,没有问题,这里它被发送到上面的 store() 函数)

cart.blade.php

...
{{ Cart::items() }}
...
@if (session()->has('success_message'))
    {{ session()->get('success_message') }}
@endif

@if (count($errors) > 0)
    @foreach ($errors->all() as $error)
       <p>{{ $error }}</p>
    @endforeach
@endif

(在切换到最新包之前,我使用 @foreach 语句逐项打印出整个购物车,但为了避免任何语法错误,我决定让它变得简单,这里 Cart::items() 应该只打印购物车内容,但它是空的:'[]').

备注:

在这一点上,我不知道我正在进入什么,我试图了解我是否遗漏了什么或者是否存在实际问题。任何人都可以帮助或建议兼容的软件包吗?提前致谢。

我们是 Laravel 的 TreeStoneIT 购物车的创建者。

很难确定,因为没有完整的资源来重现这个问题,我的猜测是具有 Buyable 特征的模型可能没有正确设置,但也可能是其他东西.

您可以在此处查看完整的工作示例:https://github.com/treeStoneIT/laravel-commerce