3
votes

I'm getting this error "Target class [App\Http\Controllers\OrderController] does not exist." when ever i run "php artisan route:list and I can't determine what or where is the problem in this code or I am just Dumb tho

<?php

namespace App\Http\Controllers;

use App\Order;
use Auth;
use Illuminate\Http\Request;

class OrderController extends Controller
{
    public function index()
    {
        return response()->json(Order::with(['product'])->get(),200);
    }

    public function deliverOrder(Order $order)
    {
        $order->is_delivered = true;
        $status = $order->save();

        return response()->json([
            'status'    => $status,
            'data'      => $order,
            'message'   => $status ? 'Order Delivered!' : 'Error Delivering Order'
        ]);
    }

    public function store(Request $request)
    {
        $order = Order::create([
            'product_id' => $request->product_id,
            'user_id' => Auth::id(),
            'quantity' => $request->quantity,
            'address' => $request->address
        ]);

        return response()->json([
            'status' => (bool) $order,
            'data'   => $order,
            'message' => $order ? 'Order Created!' : 'Error Creating Order'
        ]);
    }

    public function show(Order $order)
    {
        return response()->json($order,200);
    }

    public function update(Request $request, Order $order)
    {
        $status = $order->update(
            $request->only(['quantity'])
        );

        return response()->json([
            'status' => $status,
            'message' => $status ? 'Order Updated!' : 'Error Updating Order'
        ]);
    }

    public function destroy(Order $order)
    {
        $status = $order->delete();

        return response()->json([
            'status' => $status,
            'message' => $status ? 'Order Deleted!' : 'Error Deleting Order'
        ]);
    }
}

here is my code from my order controller please help me and Thank you in advance for helping me

5
please put your web.php.Vikas Katariya
Is the controller surely in correct folder? Sometimes if you manually rename / move files, things gets mixed up. This shouldn't cause that error, but you might want also to use App\Http\Controllers\Controller; in OrderController.kaarto
try this command always after changing config files php artisan optimize:clearHamelraj

5 Answers

0
votes

run below command

  php artisan config:cache 

or

 composer dump-autoload
0
votes

after you ensue no spelling problem between controller and route, try one of these possible solutions:

  1. run php artisan config:cache
  2. run composer dump-autoload
  3. check your web.php routes and change the forward / slash to backward \

check this link it will help

0
votes

check out the route. E.g. in my case I ve gotten similar error after setting the route in web.php . It had been written wrong:

 Route::get('/dispatch_notes/{order_id}','order\AddNotesController.php@dispatchNotes')
  ->name('dispatch_notes');

Had its name wrong copypasted from controllers folder. After suggested playings with cache clearings saw that and removed the .php off its name and got it worked.

0
votes

In laravel 8

In RouteServiceProvider uncomment

protected $namespace='App\\Http\\Controllers';
-1
votes

First check your directory your controller is in seperate folder in controler folder or it is in controller folder. If your Controller file is in new folder like Controller/YourFolder/Your file the you use in web.php route like below

Route::get('your url','YourFOlderName\COntrolername@methodname')->name('your route 
name')

I hope its work fine