duanqin9507 2017-08-07 01:44
浏览 111
已采纳

(1/1)验证我的电子邮件地址时出现NotFoundHttpException

I am new to laravel 5.4 and I am trying to practice some laravel stuffs. I want to create a feature of email verification when the applicant sign up and verifies his/her email before the applicant can login. But when I click the link below in order to verify the email address of the applicant I encounter this error. I don't know if I messed up with my route and having a hard time to resolve this. here is the link of the to verify the email address http://127.0.0.1:8000/register/verify/KafEACL1U3DxoprDI0aIVpAyM3DY8Q.

Here is the code in my route:

Route::group(['prefix' => 'applicant', 'namespace' => 'Applicant'], function () {
    Route::get('/', 'LoginController@showLoginForm');
    Route::post('/login', 'LoginController@authenticate')->name('applicant.login');
    Route::post('/logout', 'LoginController@logout')->name('logout');
    Route::get('/home', 'HomeController@index')->name('applicant.home');
    Route::get('/signup', 'LoginController@signup')->name('applicant.signup');
    Route::post('/register_check', 'LoginController@store')->name('register_check');
    Route::resource('applications', 'ApplicationController',
         ['as' => 'applicant']);
    Route::get('/verify', 'LoginController@confirm')->name('applicant.verify');
        //secured file view only by customer-relations
    Route::get('applications/print/{application_number}', [
         'as'         => 'applicant.application-form.print',
         'uses'       => 'ApplicationController@printApplicationConfirmation',
    ]);
});

Heres the code in my controller:

public function store(CreateApplicantRequest $request)
    {
        $input = $request->all();

        $confirmation_code = str_random(30);

        $data = array('confirmation_code'=>$confirmation_code);

        $applicants = $this->applicantRepository->create([
            'name' => $input['name'],
            'email' => $input['email'],
            'password' => bcrypt($input['password']),
            'address' => $input['address'],
            'cellphone_no' => $input['cellphone_no'],
            'confirmation_code' => $confirmation_code
        ]);

       Mail::send('applicant-dashboard.verify', compact('confirmation_code'), function($message) {
    $message->to(Input::get('email'), Input::get('name'))
            ->subject('Verify your email address');
});

        Flash::message('Thanks for signing up! Please check and verify your email.');

        return redirect(url('applicant'));
    }

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

        $applicant = Applicant::whereConfirmationCode($confirmation_code)->first();

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

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

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

        return Redirect::url('applicant');
    }
  • 写回答

2条回答 默认 最新

  • duanhunlou7051 2017-08-07 01:46
    关注

    change your verification link from :

    http://127.0.0.1:8000/register/verify/KafEACL1U3DxoprDI0aIVpAyM3DY8Q
    

    to

    http://127.0.0.1:8000/applicant/register/verify/KafEACL1U3DxoprDI0aIVpAyM3DY8Q
    

    because your route is under a group with a prefix of applicant

    also edit the verification route to look like this :

    Route::get('/register/verify/{confirmation_code}', 'LoginController@confirm')->name('applicant.verify');
    

    don't forget to use this import at the top of your controller file after the namespace line:

    use App\Exceptions\InvalidConfirmationCodeException;
    

    this is because laravel use psr-4 autoloading, this means that the InvalidConfirmationCodeException exception class is under 'app/Exceptions' folder.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP