如何在 Laravel 中验证电子邮件后向用户显示消息?

How to show message to the user after email verification in Laravel?

我想在电子邮件验证后向用户显示一条消息。新用户注册网站后,获取电子邮件到电子邮件验证。有一个 VerficationController。我该如何修改才能收到通知?


<?php

namespace App\Http\Controllers\Auth;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
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 = RouteServiceProvider::HOME;

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


你可以override verified这样的功能。

    protected function verified(Request $request)
{
    $request->session()->flash('alert','You message here');
}

当用户将被验证时,这将添加一个会话,然后无论你在哪里重定向,你都可以从 Session 获得消息并可以显示消息。

像这样:

@if(Session::has('alert'))
  <p class="alert {{ Session::get('alert-class', 'alert-info') }}">
    {{ Session::get('alert') }}
  </p>
@endif