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?
CodePudding user response:
As per my knowledge laravel 8 is not overriding that way of declaring routes. Example code that works fine
Route::group(
[
'prefix' => 'db-notifications',
'as' => 'notification.',
'middleware' => 'auth'
],
function () {
Route::get('/send-notification', 'NotificationsController@SendTestMail'])
->name('send');
})
CodePudding user response:
you should add this code
protected $namespace = 'App\\Http\\Controllers';
in this file RouteServiceProvider.php