当我在 Laravel 中启动该项目时,我有一个 ReturnController。但由于命名约定,我不得不将其重命名为 OrderController。我重命名了控制器和模型,我运行所有 php artisan cache:clear、php artisan route:cache、php artisan config:cache ... 等,但是当我尝试在 中创建订单时>views\orders\add.blade.php(表单的操作是action="{{route('orders.store') }}")
我收到错误目标类 [OrderController] 不存在。
这是web.php内容:
Route::get('/', function () {
return view('welcome');
});
Route::resource('customers', 'CustomerController');
Route::resource('orders', 'OrderController');
Auth::routes();
Route::get('/home', [App\Http\Controllers\OrderController::class, 'showOrders'])->name('orders');
Route::get('/orders/create', [App\Http\Controllers\OrderController::class, 'create'])->name('orders.create');
Route::get('/orders', [App\Http\Controllers\OrderController::class, 'index']);
我错过了什么?在使用正确的控制器名称从头开始重写整个应用程序之前,如何解决此问题?
另一个线索是,为了导航到 http://127.0.0.1:8000/home ,奇怪的是我必须添加行 use App\Models\Order在 OrderController.php 中以便工作...所以这里是 OrderController.php 以帮助...
get();
return view('home', compact('orders'));
}
} Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号