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

Time:02-24

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');

CodePudding user response:

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

php artisan config:cache

php artisan optimize:clear

CodePudding user response:

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
  • Related