'what's the solution here when it says Target class [SiteController] does not exist.?

i'm using laravel 9.don't know why it says "Target class [SiteController] does not exist". SiteController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class SiteController extends Controller
{
   public function home(){
        return "i am from siteController home";
    }

   public function about(){
        return "i am from siteController about";
    }

   public function contact(){
        return "i am from siteController contact";
    }
}

web.php

Route::get('/', 'SiteController@home');

Route::get('/about', 'SiteController@about');

Route::get('/contact', 'SiteController@contact');


Solution 1:[1]

Since Laravel version 8, controller route definitions must be defined using standard PHP callable syntax:

Basic Controllers

use App\Http\Controllers\SiteController;

Route::get('/', [SiteController::class, 'home']);
Route::get('/about', [SiteController::class, 'about']);
Route::get('/contact', [SiteController::class, 'contact']);

You may use the route:clear command to clear the route cache:

php artisan route:clear

Solution 2:[2]

Please run the command, I think some cache has occured.

php artisan config:cache

php artisan optimize:clear

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Wahyu Kristianto
Solution 2 Kishore Kumar