首页 > 解决方案 > 如果未验证电子邮件,则显示一条消息 Laravel

问题描述

如果电子邮件经过验证,我需要做一些事情<p>,如果可能的话,在主页上显示一些文本,而不是路线

@if(email is verified)
<p>hello there</p>
@endif
@else
<p>you need to verify your email address</p>

VerificationController.php如果我设置了一个电子邮件版本,我是否需要创建一个控制器或更改当前的:

<?php

namespace App\Http\Controllers\Auth;

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

标签: laravelemail

解决方案


这取决于您如何知道用户已通过验证。如果您有一个用户的数据库列 email_verified_at 作为可为空的日期时间,您可以执行以下操作:

//The authenticated user is verified, since there is a datetime
@if(Auth::user()->email_verified_at != null)
  //Do something
  @else
    //Do something else, since the authenticated user is not verified
@endif

推荐阅读