Laravel Moltin 购物车调用自定义存储库


Laravel Moltin Cart call in custom repository

我在Laravel 4.2上安装了Moltin Cart,并按照文档建议对其进行了配置。当我从控制器调用它时,一切都很完美。像购物车::插入()等。

问题是当我尝试在自定义存储库中调用相同的代码时。我有这个存储库/命名空间:

namespace MyApp'Repositories;
use MyApp'Interfaces'CartInterface;
class CartRepository implements CartInterface 
...

因此,当我在这个 CartRepository 类中的某些函数中调用Cart::insert时,我遇到了错误"Class 'MyApp'Repositories'Cart' not found".例如我在命名空间后尝试了许多 USE 变体,但没有任何效果。我遇到了新的错误,例如

"不应调用非静态方法 Moltin''Cart''Cart::insert() 静态地,假设$this来自不兼容的上下文"

或类似。

程序员通常的情况如何,我在提出问题后立即找到答案。在此之前,我在 1-2 小时左右徘徊。

所以,解决方案是把

使用购物车;

我尝试了所有方法,但除此之外。 :)