1
votes

Im trying to make a little crud.

Current I have this issue where it doesnt recongize my controller which I have.

Error:

Target class [App\Http\Controllers\CRUD\ProductController] does not exist.

web.php

Route::get('/CRUD', 'CRUD\ProductController@index');

Controller

class ProductController extends Controller
{
    public function index ()
    {
        $products = Products::index();
        dd($products);
        return view("CRUD.view", [ "products" => $products]);
    }
}

My file directory

3
please, attach your file structureV-K
@V-K I've editted it in.Tim
ok, run composer dump-autoload in the consoleV-K
@V-K donezo, still get the same error.Tim
Does this answer your question? Laravel : Class controller does not existHarpal Singh

3 Answers

5
votes

Check the file app/Providers/RouteServiceProvider.php and uncomment the line:

 protected $namespace = 'App\Http\\Controllers';

Then clean the cache: php artisan route:cache

4
votes

Check the ProductController file namespace, it should look like:

namespace App\Http\Controllers\CRUD;

class ProductController extends Controller
{
    public function index ()
    {
        $products = Products::index();
        dd($products);
        return view("CRUD.view", [ "products" => $products]);
    }
}
0
votes

should follow above comment check file app/Providers/RouteServiceProvider.php

and uncomment the line: protected $namespace = 'App\Http\Controllers';