Home > Blockchain >  Laravel - Target class [app\Http\Controllers\ProductsController] does not exist
Laravel - Target class [app\Http\Controllers\ProductsController] does not exist

Time:06-09

I tried several stackoverflow solutions for my problem, but none could fix the problem.

When i open my Laravel-Project and route to /products, i get the message: "Target class [app\Http\Controllers\ProductsController] does not exist".

Here are pictures of my code:

web.php

use Illuminate\Support\Facades\Route;
use app\Http\Controllers\ProductsController;

Route::get('/products', [ProductsController::class, 'index']);

Controller.php

namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}

ProductsController.php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class ProductsController extends Controller
{
    public function index() {
        return view('products.index');
    }
}

index.blade.php

<html lang="en"> 
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <h1>Products</h1>
</body>
</html>

Here is a picture of my filestructure: laravel structure

Would be so nice if you could help me, cause i really need to go on with my laravel tutorial.

CodePudding user response:

Hy again, thanks to sta´s comment i could solve the problem:

"probably a typo, try use App\Http\Controllers\ProductsController; app should be App"

Before(not working):

use app\Http\Controllers\ProductsController;

Solution:

use App\Http\Controllers\ProductsController;

iggivannaz

  • Related