Home  >  Q&A  >  body text

Controller target class does not exist?

I'm trying to follow the Larva tutorial and make a controller. This is what I have so far, it works for the person in the video, but mine says the controller cannot be found. I don't know what to do to fix it. Thanks!

web.php file:

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

PagesController.php file:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\PagesController;




class PagesController extends Controller
{
    public function home() 
    {
        return view('welcome', [
            'foo' => 'bar'
        ]);
    }
}

PagesController.php file

error message

Web.php file

P粉004287665P粉004287665210 days ago300

reply all(1)I'll reply

  • P粉647504283

    P粉6475042832024-02-27 12:48:13

    I think this is happening due to the route cache you added earlier

    php artisan optimize:clear

    Clear all cached commands

    Then check if this get('/') route is bound to the home() method on the controller

    php artisan route:list

    I hope it solves your problem..

    reply
    0
  • Cancelreply