英文:
Target class [htdocs\laravel_carrito\app\Http\Controllers\CartController] does not exist
问题
我有一个关于我的 "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');
?>
我的 CartController:
<?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 su 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 应用程序。
英文:
I have an issue with my "CartController.php" that indicates that the class Cart doesn´t exist but it exists in "C:\xampp\htdocs\laravel_carrito\vendor\darryldecode\cart\src\Darryldecode\Cart"
My route file:
<?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');
?>
My Cart:
<?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!');
}
}
?>
I´m new with PHP and Laravel and i dont known what to do here.
I expect to fix the error to use my web app.
答案1
得分: 1
将以下行进行更新:
从:
use htdocs\laravel_carrito\app\Http\Controllers\CartController;
到:
use App\Http\Controllers\CartController;
英文:
Update the following line:
use htdocs\laravel_carrito\app\Http\Controllers\CartController;
to
use App\Http\Controllers\CartController;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论