Laravelshoppingcart: Non-static method Gloudemans\Shoppingcart\Cart::add()

Created on 18 Apr 2016  路  8Comments  路  Source: Crinsane/LaravelShoppingcart

Non-static method Gloudemans\Shoppingcart\Cart::add() should not be called statically, assuming $this from incompatible context

Im using laravel 5.1 ; there i dont find any static method.
Please help !!

Most helpful comment

@ilhamsabar You will have to use the facade, you're trying to call the add method statically on the actual Cart class.

So don't do use Gloudemans\Shoppingcart\Cart; but use Cart; or use Gloudemans\Shoppingcart\Facades\Cart;.

All 8 comments

You should call the add() method on the facade, not on the actual class.

use Cart;

i try use Cart. and i find this eror.. please help. i found same eror

@ilhamsabar You will have to use the facade, you're trying to call the add method statically on the actual Cart class.

So don't do use Gloudemans\Shoppingcart\Cart; but use Cart; or use Gloudemans\Shoppingcart\Facades\Cart;.

How to get table for this LaravelShoppingcart packages?

I tried

    $c = new Cart(?,?);
    $c->add('192ao12', 'Product 1', 1, 9.99);

What to put in the hell two arguments while instantiating?

@shahidkarimi You either use the facade and call the add method on that. If you want to create an instance of the cart yourself, either use the service container, so something like app(Cart::class) or let Laravel inject it into the class constructor or something for you. If you really want to do it like the code you showed me, take a look at the actual code to see what it needs.

But there's not really any need to instantiate the cart yourself like that.

please I had the same issue i used use Cart; but it gave me a new error saying provide a valid name

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sobhanattar picture sobhanattar  路  4Comments

hatamiarash7 picture hatamiarash7  路  6Comments

nasirkhan picture nasirkhan  路  8Comments

ellgibug picture ellgibug  路  5Comments

yansentan picture yansentan  路  6Comments