Class “Inertia\Middleware” not found

Posted by

Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

Getting this Error:-

Local.ERROR: Class "Inertia\Middleware" not found {"exception":"[object] (Error(code: 0): Class \"Inertia\\Middleware\" not found at C:\\xampp-laravel\\htdocs\\Wizbrand\\wz-organisation-ms-9\\app\\Http\\Middleware\\HandleInertiaRequests.php:9)
[stacktrace]
#0 C:\\xampp-laravel\\htdocs\\Wizbrand\\wz-organisation-ms-9\\vendor\\composer\\ClassLoader.php(576): include()
#1 C:\\xampp-laravel\\htdocs\\Wizbrand\\wz-organisation-ms-9\\vendor\\composer\\ClassLoader.php(427): Composer\\Autoload\\{closure}('C:\\\\xampp-larave...')
#2 [internal function]: Composer\\Autoload\\ClassLoader->loadClass('App\\\\Http\\\\Middle...')
#3 C:\\xampp-laravel\\htdocs\\Wizbrand\\wz-organisation-ms-9\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\SortedMiddleware.php(97): class_implements('App\\\\Http\\\\Middle...')
#4 C:\\xampp-laravel\\htdocs\\Wizbrand\\wz-organisation-ms-9\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\SortedMiddleware.php(76): Illuminate\\Routing\\SortedMiddleware->middlewareNames('App\\\\Http\\\\Middle...')
#5 C:\\xampp-laravel\\htdocs\\Wizbrand\\wz-organisation-ms-9\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\SortedMiddleware.php(43): Illuminate\\Routing\\SortedMiddleware->priorityMapIndex(Array, 'App\\\\Http\\\\Middle...')
#6 C:\\xampp-laravel\\htdocs\\Wizbrand\\wz-organisation-ms-9\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\SortedMiddleware.php(22): Illuminate\\Routing\\SortedMiddleware->sortMiddleware(Array, Array)
#7 C:\\xampp-laravel\\htdocs\\Wizbrand\\wz-organisation-ms-9\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(863): Illuminate\\Routing\\SortedMiddleware->__construct(Array, Array)
#8 C:\\xampp-laravel\\htdocs\\Wizbrand\\wz-organisation-ms-9\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(852): Illuminate\\Routing\\Router->sortMiddleware(Object(Illuminate\\Support\\Collection))
#9 C:\\xampp-laravel\\htdocs\\Wizbrand\\wz-organisation-ms-9\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(810): Illuminate\\Routing\\Router->resolveMiddleware(Object(Illuminate\\Support\\Collection), Array)
#10 C:\\xampp-laravel\\htdocs\\Wizbrand\\wz-organisation-ms-9\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(792): Illuminate\\Routing\\Router->gatherRouteMiddleware(Object(Illuminate\\Routing\\Route))
#11 C:\\xampp-laravel\\htdocs\\Wizbrand\\wz-organisation-ms-9\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(776): Illuminate\\Routing\\Router->runRouteWithinStack(Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request))
#12 C:\\xampp-laravel\\htdocs\\Wizbrand\\wz-organisation-ms-9\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(740): Illuminate\\Routing\\Router->runRoute(Object(Illuminate\\Http\\Request), Object(Illuminate\\Routing\\Route))
#13 C:\\xampp-laravel\\htdocs\\Wizbrand\\wz-organisation-ms-9\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(729): Illuminate\\Routing\\Router->dispatchToRoute(Object(Illuminate\\Http\\Request))
#14 C:\\xampp-laravel\\htdocs\\Wizbrand\\wz-organisation-ms-9\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(190): Illuminate\\Routing\\Router->dispatch(Object(Illuminate\\Http\\Request))
#15 C:\\xampp-laravel\\htdocs\\Wizbrand\\wz-organisation-ms-9\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(141): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}(Object(Illuminate\\Http\\Request))

Solution:-

Step 1:- You just need to run a composer command in your project which i have given below:

composer require inertiajs/inertia-laravel

Step 2:- Then please run one more command to apply this package in your project.

php artisan inertia:middleware

Step 3:- And please check the package you have used in the following file or not.

use Inertia\Middleware;

Step 4:- And make sure that you have added the below code in the kernel.php file in your laravel project like the way i have given below.

 protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
            \App\Http\Middleware\HandleInertiaRequests::class,
            \Illuminate\Http\Middleware\AddLinkHeadersForPreloadedAssets::class,
        ],

Now your issue is solved

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x