routeslaravel-8laravel-jetstreaminertiajs

Laravel 8 JetStream BindingResolutionException Target class [App\Http\Middleware\HandleInertiaRequests] does not exist


These setting up a new laravel8 project with jetStream InertiaJs, but when I start the application I get the following error:

enter image description here

Apparently it is a route error and the blogs show the solution to edit the RouteServiceProvider.php file and define the following variable:

protected $namespace = 'App\\Http\\Controllers';
$this->routes(function () {
            Route::prefix('api')
                ->middleware('api')
                ->namespace($this->namespace)
                ->group(base_path('routes/api.php'));

            Route::middleware('web')
                ->namespace($this->namespace)
                ->group(base_path('routes/web.php'));
        });

The web file paths are as follows:

Route::get('/', function () {
    return Inertia::render('Welcome', [
        'canLogin' => Route::has('login'),
        'canRegister' => Route::has('register'),
        'laravelVersion' => Application::VERSION,
        'phpVersion' => PHP_VERSION,
    ]);
});

Route::middleware(['auth:sanctum', 'verified'])->get('/dashboard', function () {
    return Inertia::render('Dashboard');
})->name('dashboard');

but the error remains, please someone can tell me a solution or that I should review to find a solution


Solution

  • You may need to use Inertia\Inertia; at top of the PHP file before using it.