如何修复Laravel 5.7中的“类签名不存在”错误?

时间:2018-09-19 13:53:45

标签: php laravel email verification

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

2 个答案:

答案 0 :(得分:11)

看看Laravel Documentation on Signed URLs

我的猜测是您在$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,
];

答案 1 :(得分:0)

我在API电子邮件验证方面遇到了同样的问题,我不得不添加触发在app / Providers / EventServiceProvider.php中发送电子邮件的事件

protected $listen = [
    Registered::class => [
        SendEmailVerificationNotification::class,
    ],
];

和覆盖应用程序/ HTTP /控制器/认证/ VerificationController.php功能

/**
 * Show the email verification notice.
 *
 */
public function show()
{

}

/**
 * Mark the authenticated user's email address as verified.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function verify(Request $request)
{
    if ($request->route('id') == $request->user()->getKey() &&
        $request->user()->markEmailAsVerified()) {
        event(new Verified($request->user()));
    }

    return response()->json('Email verified!');
}

/**
 * Resend the email verification notification.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function resend(Request $request)
{
    if ($request->user()->hasVerifiedEmail()) {
        return response()->json('User already have verified email!', 422);
    }

    $request->user()->sendEmailVerificationNotification();

    return response()->json('The notification has been resubmitted');
}

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