php - 如何修复 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');
}
}
解决方案
$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,
];
推荐阅读
- c# - .razor 中的 TextArea 未刷新,尽管绑定到字符串变量
- r - 如何使用 R 中的索引向量将向量组合到数据框中?
- php - 如何在动态header.php中动态加载文件
- python - 将字典中的键(在列中)添加到新列
- java - 如何在 MockMVC 中发布多部分/表单数据?
- c# - 我需要编写什么函数才能从表中删除?
- javascript - 使用javascript根据第一个选择列表选项更改第二个选择列表?
- graphql - GatsbyJS / GraphQL 简单博客
- r - 排除for循环中的缺失数据
- swift - MKLocalSearchCompleter 不能在物理设备上工作,但在模拟器上工作正常