Hello Artisan,
In this tutorial, I will explain how we can solve the target class does ‘t exist in Laravel 8. You know recently laravel 8 was released some days ago. They changed the routing system a bit from other versions of Laravel.
In this tutorial we will solve laravel 8 routing problem like target class app/http/controllers does not exist. See the below code to solve this BindingResolutionException Target class does not exist.
Example code :
use App\Http\Controllers\YourController;
Route::get('/', [YourController::class, 'anyMethod']);
So in Laravel 8 you have to show the path of your controller. You can use route group to avoid path as like below.
Route::namespace('App\Http\Controllers')->middleware('guest')->group(function () {
Route::prefix('')->group(function () { //you can use prefix if you want
Route::get('/', 'YourController@anyMethod');
});
});
Or if your are not happy with the above system and you would like to use it like laravel 7 then follow the below tips. go to your route service provider and update the code like below.
app/Providers/RouteServiceProvider.php
protected $namespace = 'App\Http\Controllers';
// the add this namespace like below
$this->routes(function () {
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
now you can simply use like laravel 7 or other version
Route::get('/', 'YourController@anyMethod');
Hope it can be help you.