Search code examples
phplaravelemailverification

How to fix "Class signed does not exist" error in Laravel 5.7?


I just updated my Laravel project from 5.6 to 5.7. The primary reason I upgraded was I needed to add Email Verification to my project. After I completed all upgrade steps and implemented the Email Verification as per the Laravel documentation I am getting an error. So the steps leading up to the error is this:

I used 1 route to test with, in my ..\routes\web.php file I have this line of code:

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

When I try to go to that route it does redirect me to the view for ..\views\auth\verify.blade.php as it should. There I click the link to send the verification email. I get the email then I click the button in the email to verify my email. It launches a browser and starts to navigate me somewhere and thats when it gets an error:

Class signed does not exist

After much research I discovered the error was in the new VerificationController.php file that the instructions said to create and the line of code causing the problem is:

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

If I comment this line out and click the button in my email again then it works without any errors and my users email_verified_at column is updated with a datetime stamp.

Below is the entire VerificationController.pas in case it sheds any light on the problem:

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

Solution

  • Take a look at the Laravel Documentation on Signed URLs

    My guess is you are missing this entry in the $routeMiddleware array

    // 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,
    ];