0

I'm new to Laravel and I don't know what I am missing here. I have this in web.php

<?php

use Illuminate\Support\Facades\Route;
        Route::get('/', function () {
        return view('welcome');
    });
    
    Route::get('/Pages', 'PagesController@index');

My PagesController.php is

    <?php

namespace App\Http\Controllers;

class PagesController
{
    public function index()
    {
        echo 'Hello World';
    }
}

PagesController exists inside Http/Controllers file, but I get an error that says "Target class [PagesController] does not exist" when I go to /Pages. I definitely not have a typo in the class name and I have searched for solutions but nothing worked. Can anyone give me advice on how to fix this?

Coder
  • 131
  • 1
  • 3
  • 10
  • Welcome to SO ... https://stackoverflow.com/questions/63882034/target-class-does-not-exist-problem-in-laravel-8#answer-63882104 take a look this – Kamlesh Paul Nov 24 '20 at 04:54

1 Answers1

3

What laravel version you are working on? Laravel 6,7 or 8.

if you are working on Larvel 8 you can't write route like we used to before, the next syntax is this.

Web.php:

use App\Http\Controllers\PagesController;

Route::get('/Pages', [PagesController::class, 'index']);

or:

Route::get('/Pages', '\App\Http\Controllers\PagesController@index');

Docs for routing

Dilip Hirapara
  • 14,810
  • 3
  • 27
  • 49
Mudit Gulgulia
  • 1,131
  • 7
  • 21