如何修复Laravel 5.7中的"Class signed not exists"错误?

Way*_*her 5 php email verification laravel

我刚刚将Laravel项目从5.6更新到5.7.我升级的主要原因是我需要为我的项目添加电子邮件验证.完成所有升级步骤并根据Laravel文档实施电子邮件验证后,我收到错误消息.所以导致错误的步骤是这样的:

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

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

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

Class signed does not exist
Run Code Online (Sandbox Code Playgroud)

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

$this->middleware('signed')->only('verify');
Run Code Online (Sandbox Code Playgroud)

如果我出注释此行,然后单击我的电子邮件按钮再然后它没有任何错误,我的用户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');
    }
}
Run Code Online (Sandbox Code Playgroud)

Luk*_*den 13

查看签名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,
];
Run Code Online (Sandbox Code Playgroud)