Crinsane / LaravelShoppingcart

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

FatalThrowableError in HomeController.php line 50: Class 'Cart' not found #156

Closed MrLenh closed 8 years ago

MrLenh commented 8 years ago

Hello, After apply LaravelShoppingcart, i am facing the bug: Class 'Cart' not found I used laravel 5.2. my function: use App\Http\Requests; use Illuminate\Http\Request; use DB; use Mail; use Cart;

public function AddToCart($id) { $product_buy = DB::table('Products')->where('id',$id)->first(); Cart::add(['id'=>$id, 'name'=>$product_buy->name,'qty'=>1,'price'=>$product_buy->price,'option'=>['image'=>$product_buy->image]]); return redirect()->route('ShowCart'); } public function ShowCart() {
$content = Cart::content(); return view('interface.cart', compact('content')); }

Could you give me some advices about this?

SumonMSelim commented 8 years ago

Can you provide some more info like have you added the Service Provider on your config/app.php file and installed the package correctly or not?

mucyomiller commented 8 years ago

Cart facade is not working in laravel 5.2

mucyomiller commented 8 years ago

I can't also find out how to publish that default migration built into ShoppingcartServiceProvider and config/Cart.php

Crinsane commented 8 years ago

I can't reproduce this, tried several times, but I experience no such problems.

  1. I create a new Laravel 5.2 installation laravel new shop-test
  2. Include the package composer require gloudemans/shoppingcart
  3. Add the service provider to the providers array in config/app.php:

    Gloudemans\Shoppingcart\ShoppingcartServiceProvider::class,

  4. Add the facade alias to the aliases array in config/app.php:

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

And in the controller I use the Cart facade use Cart; And next I can use the facade perfectly fine.

Concerning the migration, indeed documentation is not up to date yet, but you can add it by running this artisan command:

artisan vendor:publish --provider="Gloudemans\Shoppingcart\ShoppingcartServiceProvider"

mucyomiller commented 8 years ago

its working perfectly its was our projects that was using old cached configuration