【问题标题】:Laravel 8 JetStream BindingResolutionException Target class [App\Http\Middleware\HandleInertiaRequests] does not existLaravel 8 JetStream BindingResolutionException 目标类 [App\Http\Middleware\HandleInertiaRequests] 不存在
【发布时间】:2021-04-16 22:00:27
【问题描述】:

这些使用 jetStream InertiaJs 设置了一个新的 laravel8 项目,但是当我启动应用程序时出现以下错误:

显然这是一个路由错误,博客显示了编辑 RouteServiceProvider.php 文件并定义以下变量的解决方案:

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'));
        });

网页文件路径如下:

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');

但错误仍然存​​在,请有人告诉我一个解决方案,或者我应该查看以找到解决方案

【问题讨论】:

    标签: routes laravel-8 jetstream inertiajs


    【解决方案1】:

    在使用 PHP 文件之前,您可能需要在 PHP 文件顶部添加use Inertia\Inertia;

    【讨论】:

      【解决方案2】:

      根据错误,您可能错过了 App. 将其如下放入您的 web.php 文件中: \App\Http\Middleware\HandleInertiaRequests::class

      【讨论】:

        【解决方案3】:

        按照此处的说明进行操作: https://inertiajs.com/server-side-setup

        composer require inertiajs/inertia-laravel
        php artisan inertia:middleware
        

        然后应该找到类。注意到该类无法在 IDE 中解析,因此假设默认情况下未安装该类。

        【讨论】:

          猜你喜欢
          • 2021-07-13
          • 1970-01-01
          • 2021-02-12
          • 2021-09-15
          • 2021-09-04
          • 2021-05-12
          • 1970-01-01
          • 2017-12-04
          • 1970-01-01
          相关资源
          最近更新 更多