首页 > 解决方案 > 如何修复 Laravel 5.7 中的“类签名不存在”错误?

问题描述

我刚刚将我的 Laravel 项目从 5.6 更新到了 5.7。我升级的主要原因是我需要将电子邮件验证添加到我的项目中。在我按照 Laravel 文档完成所有升级步骤并实施电子邮件验证后,我收到了一个错误。所以导致错误的步骤是这样的:

我使用 1 条路由进行测试,在我的 ..\routes\web.php 文件中我有这行代码:

Route::get('dashboard', ['uses' => 'DashboardController@getDashboard'])->middleware('verified');

当我尝试去那条路线时,它确实将我重定向到 ..\views\auth\verify.blade.php 的视图。在那里我单击链接以发送验证电子邮件。我收到电子邮件,然后单击电子邮件中的按钮以验证我的电子邮件。它启动一个浏览器并开始在某个地方导航我,这就是它出现错误的时候:

Class signed does not exist

经过大量研究,我发现错误出现在新的 VerificationController.php 文件中,说明要创建该文件,导致问题的代码行是:

$this->middleware('signed')->only('verify');

如果我将此行注释掉并再次单击电子邮件中的按钮,则它可以正常工作,并且我的用户 email_verified_at 列将使用日期时间戳进行更新。

下面是整个 VerificationController.pas,以防它阐明问题:

<?php

namespace App\Http\Controllers\Auth;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\VerifiesEmails;

class VerificationController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Email Verification Controller
    |--------------------------------------------------------------------------
    |
    | This controller is responsible for handling email verification for any
    | user that recently registered with the application. Emails may also
    | be re-sent if the user didn't receive the original email message.
    |
    */
    use VerifiesEmails;
    /**
     * Where to redirect users after verification.
     *
     * @var string
     */
    protected $redirectTo = '/dashboard';
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
        $this->middleware('signed')->only('verify');
        $this->middleware('throttle:6,1')->only('verify', 'resend');
    }
}

标签: phplaravelemailverification

解决方案


查看有关签名 URL 的 Laravel 文档

$routeMiddleware我的猜测是您在数组中缺少此条目

// In app\Http\Kernel.php
/**
 * The application's route middleware.
 *
 * These middleware may be assigned to groups or used individually.
 *
 * @var array
 */
protected $routeMiddleware = [
    ...
    'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
];

推荐阅读