Search code examples
laravellaravel-routinglaravel-8

Laravel Target class [register] does not exist after migrate from version 5.8 to 8


I had project in Laravel 5.8 and I created new project in Laravel 8 and moved files with code into new project. My routes files has route:

use App\Http\Controllers\AccountController;
use Illuminate\Routing\Router;

/* @var $router \Illuminate\Routing\Router */
$router->get('/', ['uses' => 'PageController@home', 'as' => 'home']);

$router->group(['prefix' => 'account', 'middleware' => ['register', 'no-cache', 'timezone']], function (Router $router) {
   // $router->get('/dashboard', ['uses' => 'AccountController@dashboard', 'as' => 'account.dashboard']);
    $router->get('/dashboard', [AccountController::class, 'dashboard'])->name('account.dashboard');

When I type home in in url view is displayed. But when I type /account/dashboard I get error:

Illuminate\Contracts\Container\BindingResolutionException
Target class [register] does not exist.

Something is wrong with middleware? Why first routing with PageController and home works but account.dashboard doesn't work in both cases (first is commented)

In RouteServiceProvider I uncommented line:

protected $namespace = 'App\\Http\\Controllers';

Now it works, I forgot to add in app\Http\Kernel.php:

protected $routeMiddleware = [
        ...
        'admin' => AdminMiddleware::class,
    ]; 

and router cannot find admin prefix


Solution

  • As Robert pointed out in the comment section, in app\Http\Kernel.php 'admin' was missing. Apparently the solution was to add an item accordingly to the $routeMiddleware array, shown by Robert as

    protected $routeMiddleware = [
            ...
            'admin' => AdminMiddleware::class,
        ];