找到你要的答案

Q:InvalidConfirmationCode not Found exception in laravel 5

Q:invalidconfirmationcode未发现laravel 5例外

I am trying to send a verfication link after the user completes registration in my web app. I have successfully sent an email to the user but when I click the link in the email I get this error

Class 'App\Http\Controllers\InvalidConfirmationCodeException' not found

This is my Controller

 public function confirm($code)
    {
        if( ! $code)
        {
            throw new InvalidConfirmationCodeException;
        }

        $user = User::whereConfirmationCode($code)->first();

        if (!$user)
        {
            throw new InvalidConfirmationCodeException;
        }

        $user->confirmed = 1;
        $user->confirmation_code = null;
        $user->save();

        Flash::message('You have successfully verified your account.');

        return Redirect::to('/login');
    }

What is the possible error? please help

我想在我的Web应用程序的用户完成注册后发送一个验证链接。我已经成功地发送电子邮件给用户,但当我点击电子邮件中的链接,我得到这个错误

Class 'App\Http\Controllers\InvalidConfirmationCodeException' not found

这是我的控制器

 public function confirm($code)
    {
        if( ! $code)
        {
            throw new InvalidConfirmationCodeException;
        }

        $user = User::whereConfirmationCode($code)->first();

        if (!$user)
        {
            throw new InvalidConfirmationCodeException;
        }

        $user->confirmed = 1;
        $user->confirmation_code = null;
        $user->save();

        Flash::message('You have successfully verified your account.');

        return Redirect::to('/login');
    }

可能的错误是什么?请帮助

answer1: 回答1:

Your InvalidConfirmationCodeException is probably in another namespace than App\Http\Controllers, that's why it can't be found. Use namespaced class name

throw new \Your\Exceptions\Namespace\InvalidConfirmationCodeException;

or import the exception class using use statement at the top of your controller file:

<?php namespace App\Http\Controllers;

use Your\Exceptions\Namespace\InvalidConfirmationCodeException;

你的invalidconfirmationcodeexception可能是在另一个命名空间比应用HTTP \控制器,这就是为什么它不能被发现。使用命名空间的类名称

throw new \Your\Exceptions\Namespace\InvalidConfirmationCodeException;

或使用控制器文件顶部的使用语句导入异常类:

<?php namespace App\Http\Controllers;

use Your\Exceptions\Namespace\InvalidConfirmationCodeException;
php  email  laravel  laravel-5  laravel-5.1