lundi 18 octobre 2021

Getting error "Target Class Not Found" while trying to use old way of calling controllers at web.php

I'm using Laravel 8 and I wanted to use the old way of calling controller and routes in web.php.

So instead of saying this:

Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');

I would call the Controller like this:

Route::get('/home', 'HomeController@index')->name('home');

So I added this to AppServiceProvider.php:

public function boot()
    {
        Route::prefix('web')
            ->middleware('web')
            ->namespace('App\Http\Controllers') // <---------
            ->group(base_path('routes/web.php'));
    }

But it doesn't seem to be working because I'm getting this error:

Target class [HomeController] does not exist.

So how can I call my Controller at web.php like the old style which was used in Laravel 5 versions?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire