Target class [htdocs\laravel_carrito\app\Http\Controllers\CartController] does not exist.

huangapple go评论64阅读模式
英文:

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:

&lt;?php
use Illuminate\Support\Facades\Route;
use htdocs\laravel_carrito\app\Http\Controllers\CartController;
Route::get(&#39;/&#39;, [CartController::class, &#39;shop&#39;])-&gt;name(&#39;shop&#39;);
Route::get(&#39;/cart&#39;, [CartController::class, &#39;cart&#39;])-&gt;name(&#39;cart.index&#39;);
Route::post(&#39;/add&#39;, [CartController::class, &#39;add&#39;])-&gt;name(&#39;cart.store&#39;);
Route::post(&#39;/update&#39;, [CartController::class, &#39;update&#39;])-&gt;name(&#39;cart.update&#39;);
Route::post(&#39;/remove&#39;, [CartController::class, &#39;remove&#39;])-&gt;name(&#39;cart.remove&#39;);
Route::post(&#39;/clear&#39;, [CartController::class, &#39;clear&#39;])-&gt;name(&#39;cart.clear&#39;);
Route::get(&#39;/shop&#39;, [App\Http\Controllers\CartController::class, &#39;shop&#39;])-&gt;name(&#39;shop.index&#39;);
Route::get(&#39;/cart&#39;, [App\Http\Controllers\CartController::class, &#39;cart&#39;])-&gt;name(&#39;cart.index&#39;);
Route::post(&#39;/cart-add&#39;, [App\Http\Controllers\CartController::class, &#39;add&#39;])-&gt;name(&#39;cart.add&#39;);
Route::post(&#39;/cart-remove&#39;, [App\Http\Controllers\CartController::class, &#39;remove&#39;])-&gt;name(&#39;cart.remove&#39;);
Route::post(&#39;/cart-update&#39;, [App\Http\Controllers\CartController::class, &#39;update&#39;])-&gt;name(&#39;cart.update&#39;);
Route::get(&#39;/cart-clear&#39;, [App\Http\Controllers\CartController::class, &#39;clear&#39;])-&gt;name(&#39;cart.clear&#39;);
?&gt;

My Cart:

&lt;?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(&#39;shop&#39;)-&gt;withTitle(&#39;E-COMMERCE STORE | SHOP&#39;)-&gt;with([&#39;products&#39; =&gt; $products]);
}
public function cart()  {
$cartCollection = \Cart::getContent();
//dd($cartCollection);
return view(&#39;cart&#39;)-&gt;withTitle(&#39;E-COMMERCE STORE | CART&#39;)-&gt;with([&#39;cartCollection&#39; =&gt; $cartCollection]);;
}
public function remove(Request $request){
\Cart::remove($request-&gt;id);
return redirect()-&gt;route(&#39;cart.index&#39;)-&gt;with(&#39;success_msg&#39;, &#39;Item is removed!&#39;);
}
public function add(Request$request){
\Cart::add(array(
&#39;id&#39; =&gt; $request-&gt;id,
&#39;name&#39; =&gt; $request-&gt;name,
&#39;price&#39; =&gt; $request-&gt;price,
&#39;quantity&#39; =&gt; $request-&gt;quantity,
&#39;attributes&#39; =&gt; array(
&#39;image&#39; =&gt; $request-&gt;img,
&#39;slug&#39; =&gt; $request-&gt;slug
)
));
return redirect()-&gt;route(&#39;cart.index&#39;)-&gt;with(&#39;success_msg&#39;, &#39;Item Agregado a s&#250; Carrito!&#39;);
}
public function update(Request $request){
\Cart::update($request-&gt;id,
array(
&#39;quantity&#39; =&gt; array(
&#39;relative&#39; =&gt; false,
&#39;value&#39; =&gt; $request-&gt;quantity
),
));
return redirect()-&gt;route(&#39;cart.index&#39;)-&gt;with(&#39;success_msg&#39;, &#39;Cart is Updated!&#39;);
}
public function clear(){
\Cart::clear();
return redirect()-&gt;route(&#39;cart.index&#39;)-&gt;with(&#39;success_msg&#39;, &#39;Car is cleared!&#39;);
}
}
?&gt;

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;

huangapple
  • 本文由 发表于 2023年3月9日 19:28:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/75683983.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定