When I start this project in Laravel, I have a ReturnController. But due to naming convention, I had to rename it to OrderController. I renamed the controller and model, I ran all php artisan cache:clear, php artisan route:cache, php artisan config:cache ...
etc. but when I try to create in When ordering>views\orders\add.blade.php
(The action of the form is action="{{route('orders.store') }}"
)
I get the errorThe target class [OrderController] does not exist.
This is web.php
Content:
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']);
What did I miss? How can I fix this before rewriting the entire application from scratch with the correct controller names?
Another clue is that in order to navigate to http://127.0.0.1:8000/home
, strangely I have to add the line use App\Models\Order
in the OrderController .php in order to work...so here is OrderController.php to help...
<?php namespace App\Http\Controllers; use App\Models\Order; use App\Models\Customer; use App\Models\Product; use Illuminate\Http\Request; class OrderController extends Controller { /** * Display a listing of the resource. */ public function index() { // } /** * Show the form for creating a new resource. */ public function create() { $customers = Customer::all(); $products = Product::all(); return view('orders.add', compact('customers', 'products')); } /** * Store a newly created resource in storage. */ public function store(Request $request) { // } /** * Display the specified resource. */ public function show(string $id) { // } /** * Show the form for editing the specified resource. */ public function edit(string $id) { // } /** * Update the specified resource in storage. */ public function update(Request $request, string $id) { // } /** * Remove the specified resource from storage. */ public function destroy(string $id) { // } public function showOrders() { $orders = Order::with(['customer', 'products'])->get(); return view('home', compact('orders')); } }
In web.php instead of:
use: