Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
667 views
in Technique[技术] by (71.8m points)

laravel - Non-static method GloudemansShoppingcartCart::add() should not be called statically

I downloaded the following library for laravel 8 shoppingcart https://github.com/hardevine/LaravelShoppingcart my composer.json

    "require": {
    "php": "^7.3|^8.0",
    "fideloper/proxy": "^4.4",
    "fruitcake/laravel-cors": "^2.0",
    "guzzlehttp/guzzle": "^7.0.1",
    "hardevine/shoppingcart": "^2.9",
    "laravel/framework": "^8.12",
    "laravel/tinker": "^2.5"
}

my shoppingcartController:

namespace AppHttpControllers;
use GloudemansShoppingcartCart;
use AppModelsProducts;
use IlluminateHttpRequest;

class ShoppingcartController extends Controller
{
    public function add(){
    $product=Products::find(request('id'));

   Cart::add($product->id, $product->product_name, 1, $product->price);
   return redirect()->route('shoppingCart')
   ->with('message_type','success')
   ->with('message','ürün sepete eklendi.');

}}

I save and refresh the page I get an error -->Non-static method GloudemansShoppingcartCart::add() should not be called statically


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

config/App Add a new line to the providers array:

GloudemansShoppingcartShoppingcartServiceProvider::class

And optionally add a new line to the aliases array:

'Cart' => GloudemansShoppingcartFacadesCart::class,

my shoppingcartController :

use Cart;

It happened when I used these commands.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...