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 App\Http\Controllers;
use Gloudemans\Shoppingcart\Cart;
use App\Models\Products;
use Illuminate\Http\Request;
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 Gloudemans\Shoppingcart\Cart::add() should not be called statically
config/App Add a new line to the providers array:
Gloudemans\Shoppingcart\ShoppingcartServiceProvider::class
And optionally add a new line to the aliases array:
'Cart' => Gloudemans\Shoppingcart\Facades\Cart::class,
my shoppingcartController :
use Cart;
It happened when I used these commands.