php 目标类[htdocs\laravel_carrito\app\Http\控制器\推车控制器]不存在

fnvucqvd  于 2023-03-11  发布在  PHP
关注(0)|答案(1)|浏览(140)

我的“CartController.php”有一个问题,表明类Cart不存在,但它存在于“C:\xampp\htdocs\laravel_carrito\vendor\darryldecode\cart\src\Darryldecode\Cart”中
我的路线文件:

<?php

use Illuminate\Support\Facades\Route;
use htdocs\laravel_carrito\app\Http\Controllers\CartController;

Route::get('/', [CartController::class, 'shop'])->name('shop');
Route::get('/cart', [CartController::class, 'cart'])->name('cart.index');
Route::post('/add', [CartController::class, 'add'])->name('cart.store');
Route::post('/update', [CartController::class, 'update'])->name('cart.update');
Route::post('/remove', [CartController::class, 'remove'])->name('cart.remove');
Route::post('/clear', [CartController::class, 'clear'])->name('cart.clear');
Route::get('/shop', [App\Http\Controllers\CartController::class, 'shop'])->name('shop.index');
Route::get('/cart', [App\Http\Controllers\CartController::class, 'cart'])->name('cart.index');
Route::post('/cart-add', [App\Http\Controllers\CartController::class, 'add'])->name('cart.add');
Route::post('/cart-remove', [App\Http\Controllers\CartController::class, 'remove'])->name('cart.remove');
Route::post('/cart-update', [App\Http\Controllers\CartController::class, 'update'])->name('cart.update');
Route::get('/cart-clear', [App\Http\Controllers\CartController::class, 'clear'])->name('cart.clear');

?>

我的购物车:

<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Product;

class CartController extends Controller
{
    public function shop()
    {
        $products = Product::all();
       //dd($products);
        return view('shop')->withTitle('E-COMMERCE STORE | SHOP')->with(['products' => $products]);
    }

    public function cart()  {
        $cartCollection = \Cart::getContent();
        //dd($cartCollection);
        return view('cart')->withTitle('E-COMMERCE STORE | CART')->with(['cartCollection' => $cartCollection]);;
    }
    public function remove(Request $request){
        \Cart::remove($request->id);
        return redirect()->route('cart.index')->with('success_msg', 'Item is removed!');
    }

    public function add(Request$request){
        \Cart::add(array(
            'id' => $request->id,
            'name' => $request->name,
            'price' => $request->price,
            'quantity' => $request->quantity,
            'attributes' => array(
                'image' => $request->img,
                'slug' => $request->slug
            )
        ));
        return redirect()->route('cart.index')->with('success_msg', 'Item Agregado a sú Carrito!');
    }

    public function update(Request $request){
        \Cart::update($request->id,
            array(
                'quantity' => array(
                    'relative' => false,
                    'value' => $request->quantity
                ),
        ));
        return redirect()->route('cart.index')->with('success_msg', 'Cart is Updated!');
    }

    public function clear(){
        \Cart::clear();
        return redirect()->route('cart.index')->with('success_msg', 'Car is cleared!');
    }
}

?>

我是PHP和Laravel的新手,我不知道在这里该怎么做。
我希望修复错误以使用我的Web应用。

neekobn8

neekobn81#

更新以下行:

use htdocs\laravel_carrito\app\Http\Controllers\CartController;

use App\Http\Controllers\CartController;

相关问题