Search code examples
phplaraveldockerubuntuwindows-subsystem-for-linux

Target class [App\Http\Middleware\HandleInertiaRequests] does not exist


Here I am starting my laravel application using:

user@Grieg:~/DevProjects/first-app $ ./vendor/bin/sail up

But when I try to open http://localhost I am receiving these errors:

Illuminate
 \ 
Contracts
 \ 
Container
 \ 
BindingResolutionException
PHP 8.2.6
10.11.0
Target class [App\Http\Middleware\HandleInertiaRequests] does not exist.

Here I see it in the \App\Http\kernel.php file:

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,
        HandleInertiaRequests::class,
        \Illuminate\Http\Middleware\AddLinkHeadersForPreloadedAssets::class,
    ],

Here is the request:

http://localhost/
GET
curl "http://localhost/" \
   -X GET \
   -H 'host: localhost' \
   -H 'connection: keep-alive' \
   -H 'cache-control: max-age=0' \
   -H 'sec-ch-ua: "Google Chrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24"' \
   -H 'sec-ch-ua-mobile: ?0' \
   -H 'sec-ch-ua-platform: "Windows"' \
   -H 'upgrade-insecure-requests: 1' \
   -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36' \
   -H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7' \
   -H 'sec-fetch-site: same-origin' \
   -H 'sec-fetch-mode: navigate' \
   -H 'sec-fetch-user: ?1' \
   -H 'sec-fetch-dest: document' \
   -H 'referer: http://localhost/' \
   -H 'accept-encoding: gzip, deflate, br' \
   -H 'accept-language: en-CA,en-GB;q=0.9,en-US;q=0.8,en;q=0.7' \
   -H 'cookie: remember_web_59ba36addc2b2f9401580f014c7f58ea4e30989d=eyJpdiI6IkVkY3BZTXc5N3BUbFhiOEdrQUxSNlE9PSIsInZhbHVlIjoiaHZIRmlsSUM2Z2p3SlBWNG1HeUNpeWthe

Does anyone have any suggestions? How can I download or import the required dependencies?


Solution

  • I switched to a new laravel breeze template to blade from vue so that no it longer requires Inertia / HandleInertiaRequests but it still had that reference in my Kernel.php, which is why I am getting the above error. To see the code changes that fixed the error please check:

    $ git log -p Kernel.php
    commit 68586c061af4e1f488dd3fae91fca9b0d93a8a63 (HEAD -> master, origin/master, origin/HEAD)
    Date:   Mon May 22 19:14:36 2023 -0600
    
        -Changed from breeze vuejs to blade
    
    diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php
    index 55442cb..bb2d8cb 100644
    --- a/app/Http/Kernel.php
    +++ b/app/Http/Kernel.php
    @@ -16,7 +16,6 @@ class Kernel extends HttpKernel
         protected $middleware = [
             // \App\Http\Middleware\TrustHosts::class,
             \App\Http\Middleware\TrustProxies::class,
    -        \Illuminate\Http\Middleware\HandleCors::class,
             \App\Http\Middleware\PreventRequestsDuringMaintenance::class,
             \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
             \App\Http\Middleware\TrimStrings::class,
    @@ -36,21 +35,19 @@ class Kernel extends HttpKernel
                 \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,
             ],
    
             'api' => [
                 // \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
    -            \Illuminate\Routing\Middleware\ThrottleRequests::class.':api',
    +            'throttle:api',
                 \Illuminate\Routing\Middleware\SubstituteBindings::class,
             ],
         ];
    
         /**
    -     * The application's middleware aliases.
    +     * The application's route middleware.
          *
    -     * Aliases may be used instead of class names to conveniently assign middleware to routes and groups.
    +     * These middleware may be assigned to groups or used individually.
          *
          * @var array<string, class-string|string>
          */