Crinsane / LaravelShoppingcart

A simple shopping cart implementation for Laravel
MIT License
3.67k stars 1.73k forks source link

Class "Cart" not found #655

Closed KishwerWali54 closed 2 years ago

KishwerWali54 commented 3 years ago

Hello,

I am facing this error Class "Cart" not found while using it in the controller.

I have given the Providers and aliases correctly which are as followinf respectively:

Gloudemans\Shoppingcart\ShoppingcartServiceProvider::class,

'Cart' => Gloudemans\Shoppingcart\Facades\Cart::class,

And I also mentioned Use Cart at the top. Can anyone help? p.s. I am using Laravel 8

bumbummen99 commented 3 years ago

How do you use Cart in your controller? If you use it without a use directive, i.e. the alias, you will have to use the global namespace like so:

\Cart::

Without the prefix slash you would use class Cart from within your Controller namespace, as Cart:: would become \App\Http\Controllers\Cart::, where it does not exist.

KishwerWali54 commented 3 years ago

My Provider is:

Gloudemans\Shoppingcart\ShoppingcartServiceProvider::class,

and Alias is:

'Cart' => Gloudemans\Shoppingcart\Facades\Cart::class,

and My Controller is:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Cart;

class CartController extends Controller
{
    //
    public function add()
    {
        Cart::add('192ao12', 'Product 1', 1, 9.99);

        $cart= Cart::content();

        return back()->with('feedback','Item is added into cart');
    }

}
moizfyaa commented 2 years ago

This is not helpfull