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?

1

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.